需要帮助来停止BackgroundWorker线程.我试图阻止后台工作线程.这就是我在做的事情:
在停止按钮单击(UI图层):
if (backgroundWorker.IsBusy == true &&
backgroundWorker.WorkerSupportsCancellation == true)
{
backgroundWorker.CancelAsync();
}
Run Code Online (Sandbox Code Playgroud)
在DoWork事件(UI层)上:
if ((backgroundWorker.CancellationPending == true))
{
e.Cancel = true;
}
else
{
//Function which progresses the progress bar is called
//here with its definition in business layer
}
Run Code Online (Sandbox Code Playgroud)
一旦DoWork事件被触发并且我的程序控件在Business层中定义的函数中,我如何恢复到DoWork事件以设置'e.Cancel = true'?