如何重新运行BackgroundWorker
我需要在 DoWork 期间捕获错误,如果错误属于某种类型,请重新运行相同的 BachgroundWorker。已尝试取消它并在 Completed
事件期间调用 RunWorkerAsync()
,但没有成功(出现异常,表明我的后台工作对象已取消)。
I need to catch error during DoWork
and if the error is of some type- re-run the same BachgroundWorker. Already tried to cancel it and call RunWorkerAsync()
during Completed
event, but no luck(exception appears saying that my backgroundworker object was canceled).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测 Bgw 仍处于错误/已取消状态,直到完成事件完成。
几个选项:
Bgw 本身并不昂贵,因此重用特定实例没有什么意义。线程来自ThreadPool。
I would guess that the Bgw remains in the Error/Canceled state until the Completed event has finished.
A few options:
A Bgw itself is not expensive so there is little point in reusing a specific instance. The threads come from the ThreadPool.