Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:19:54+00:00 2026-06-16T00:19:54+00:00

This is the dowork code. I have even stepped through this. After e.cancel =

  • 0

This is the dowork code. I have even stepped through this. After e.cancel = true, DoWork runs once more ,it gets to the while loop, it sets e.Cancel to true again and then exits the function and never runs the Completed function.

private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;
        //While the song is not over
          while (!worker.CancellationPending )
          {

              if (progressBar1.Value == progressBar1.Maximum)
              {

                  e.Cancel = true;
                  return;
              }
              else
              {
                  //Keep ticking the progress bar one second
                  worker.ReportProgress(0);
                  Thread.Sleep(1000);
              }
          }
          e.Cancel = true;
          return;



    }

Here is the code that cancels the worker. the WaitOne() will block untill it gets a signal from the RunWorkerCompleted.

if (this.backgroundWorker2.IsBusy)
        {
            this.backgroundWorker2.CancelAsync();

            _resetEvent.WaitOne();

        }

EDIT: Note that I have done this VV

backgroundWorker2.RunWorkerCompleted += backgroundWorker2_RunWorkerCompleted;
backgroundWorker2.WorkerSupportsCancellation = true;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:19:55+00:00Added an answer on June 16, 2026 at 12:19 am

    did you set

    BackgroundWorker.WorkerSupportsCancellation = true
    

    ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this code that runs a workerthread and whatnot. I shortened it
Is this possible? What I want to do is have my doWork method instantiate
I typically have code like this on a form: private void PerformLongRunningOperation() { BackgroundWorker
While looking at the source code of System.ServiceModel.Channels.BufferManager, I noticed this method: void TuneQuotas()
I have written this code for a Message Receiving class that uses a backgroundworker
I have this code : private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker
I have this code: BeginInvoke(new Action(() => tempNamesAndTexts.ForEach(Item => textBox1.AppendText(DateTime.Now + ===> + Item
Note: This code works now. I have fixed some stupid mistake and I have
Please help me to convert this below code to vb.net. I have no idea
Hey, I have a sequence of code that goes something like this: label.Text =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.