0

我的代码中有一个问题,你的 backgroundWorker 启动了两次。因此,我正在尝试 set_WorkerSupportsCacellation 以便在backgroundWorker1.IsBusy使用backgroundWorker1.CancelAsync. 但是,当我执行以下操作时:

this.backgroundWorker1.set_WorkerSupportsCancellation(true);

我得到一个编译错误:

'System.ComponentModel.BackgroundWorker.WorkerSupportsCancellation.set':无法显式调用运算符或访问器

有谁知道我如何将其设置为 true?

我用谷歌搜索了这个问题,但没有看到答案。到目前为止,我发现以下链接没有帮助: 取消线程 http://www.c-sharpcorner.com/uploadfile/Ashush/using-the-backgroundworker-component/

谢谢!

4

3 回答 3

2

我不确定set_WorkerSupportsCancellation(true)从哪里来,但电话应该是:

 backgroundWorker1.WorkerSupportsCancellation = true;
于 2012-10-10T15:02:57.490 回答
2

在 C# 程序中,如果显式调用属性 setter/getter(编译器生成的方法)或 C# 运算符映射到的方法,则会被视为错误。

于 2012-10-10T15:21:44.447 回答
0

我看到了。在属性窗口中,有一个 WorkerSupportsCancellation 选项,我将其设置为 true。呼!!谢谢您的帮助!

于 2012-10-10T17:25:47.553 回答