.Net 后台工作人员未取消

发布于 2024-09-29 03:02:11 字数 136 浏览 3 评论 0原文

我在用户控制级别使用后台工作程序,它工作正常。但后来我将工作程序推入其中一个帮助程序功能中。我的问题是,它工作正常,直到我尝试取消任务。在 DoWork 函数中,每次都有一个循环调用 Web 服务,在调用该服务之前,它会检查取消挂起,如果是,则应该中断循环。

I was using Background worker at the user control level and it was working fine.But then I pushed the worker in one of the Helper function.My question is that it works fine until i try to cancel the task. In the DoWork function there is loop calling the web service each time and before calling the service it check cancellation pending and if yes then it should break the loop.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生活了然无味 2024-10-06 03:02:11

1) 确保您已将 BackgroundWorker 上的 WorkerSupportsCancellation 属性设置为 True

2) 确保您正确处理任何 Web 服务引用。 (只是因为这是您无论如何都应该做的事情)

您可能还想单步执行BackgroundWorker 并验证取消时,取消挂起属性是否设置为true。

如果这些都没有帮助,那么您可能需要考虑显示用于创建和启动后台工作程序的代码,以及事件的任何代码(DoWork、RunWorkerCompleted 等)。

编辑(当威尔执行编辑时,此内容已被删除)

您可能还想查看此链接

从该链接中得到的一个重要信息是,即使您取消,如果工作人员已经在工作(即:通过 DoWork 进行处理),它可能会错过取消挂起并继续工作。

1) Make sure that you have set the WorkerSupportsCancellation property on your BackgroundWorker to True.

2) Make sure that you are properly disposing any web service reference. (Just because it's what you should be doing anyway)

You may also want to step through the BackgroundWorker and verify that when cancelled, the cancellation pending property is being set to true.

If none of these things help, then you might want to consider showing the code for creating and starting your backgroundworker, as well as any code for the events (DoWork, RunWorkerCompleted, etc).

EDIT (this got removed when Will performed an edit)

You may also want to check out this link.

An imporant thing to get from that link is that even when you cancel, if the worker is already doing work (IE: processing through DoWork) it can miss the cancellationpending and continue it's work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文