后台工作程序RunWorkerCompleted从未被解雇
本文关键字:工作程序 RunWorkerCompleted 后台 | 更新日期: 2023-09-27 18:22:47
使用以下代码,我的后台工作人员RunWorkerCompleted
从未被调用,我不知道为什么。
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();
}
}
我的目标是让后台工作人员连续运行,我在.NET中也有这样的工作,但当我现在用C#重写代码时,我遇到了这个问题。
是否正确连接了所有事件??
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
backgroundWorker1_RunWorkerCompleted);