如何取消繁忙的backgroundWorker vb.net [英] How to cancel a busy backgroundWorker vb.net
问题描述
我有一个后台工作人员,我通过单击bw.RunWorkerAsync()来启动按钮.我的后台工作人员内部有一个无限循环.现在,我想在单击另一个按钮时取消它.我尝试了bw.CancelAsync(),但是除非bw完成工作,否则它不起作用.但就我自己而言,由于内部无限循环,bw永远无法完成工作.那么,即使忙碌时,我该如何终止" bw?
我需要单击一个按钮来终止它.我正在使用vb.net
请帮帮我!
I have a background worker which i started on the click of a button with bw.RunWorkerAsync(). I have an infinite loop inside the backgroundworker. Now i want to cancel it at the click of another button. I tried bw.CancelAsync() but it did not work except if the bw finish working. But in my own case, the bw can never finish working because of the infinite loop inside it. So how do i "terminate" the bw even when it is busy?
I need to terminate it at the click of a button. I am using vb.net
pls help me!
推荐答案
在您的DoWork
方法中,您是否检查工人CancellationPending
属性是否正确?当该属性为true时,应将DoWorkEventArgs.Cancel
设置为true并退出该方法.
In yourDoWork
method, do yuo check if the workerCancellationPending
property is true? When that property is true, you should set theDoWorkEventArgs.Cancel
to true and exit the method.
非常感谢!奏效了!
这篇关于如何取消繁忙的backgroundWorker vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!