Backgroundworker不会停止

时间:2014-06-07 11:04:40

标签: c# .net asynchronous backgroundworker

DoWork就是这样:

        DoLengthyWork();

        //this is never executed
        if(bgWorker.CancellationPending)
        {
            MessageBox.Show("Up to here? ...");
            e.Cancel = true;
        }

我使用bgWorker.CancelAsync();

触发取消

如果无法访问 bgWorker.CancellationPending ,因为它被DoLengthyWork阻止我可以如何停止BackGround Worker?

1 个答案:

答案 0 :(得分:0)

您的问题是,DoWork功能的执行不会达到CancellationPending条件。事实上,正如balexandre所说,您应该知道组织DoLengthyWork场景以定期检查CancellationPending条件。