简体   繁体   中英

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.

Do you have all the events hooked up correctly ??

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM