Peter
Peter

Reputation: 5121

Background worker RunWorkerCompleted is never fired

Using the following code my background worker RunWorkerCompleted is never called and I can't figure out why.

void startWaitScan()
{
    backgroundWorker1.RunWorkerAsync();
}

void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    // do something here
}

void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    Console.WriteLine("BackgroundWorker1_RunWorkerCompleted");
    if (!stopAsync)
    {
        backgroundWorker1.RunWorkerAsync();
    }
}

My goal is for the background worker to run continuously, I had this working in .NET but when I rewrote the code now in C# I'm having this issue.

Upvotes: 1

Views: 4581

Answers (1)

Rwiti
Rwiti

Reputation: 1066

Do you have all the events hooked up correctly ??

 backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
 backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                                                 backgroundWorker1_RunWorkerCompleted);

Upvotes: 9

Related Questions