Winforms: Background worker - best way to KILL it
I noticed the background worker has a backgroundWorker1.CancelAsync(); method, but when you call this method, you still need to add code in the worker method开发者_开发百科, to check for a cancellation request. All this is polite and fine, but what if you just want to KILL the thread immediately? How is this done.
I want to annihilate the thread, do not pass begin and do not collect 200.
It doesn't look like a good idea...
A better programmer practice should be to check CancellationPending regularly on the thread.
if (backgroundWorker1.CancellationPending)
{
e.Cancel = true;
return;
}
EDIT:
Anyway the backgroundworker doesn't support it (as it's a bad programming practice), But if you really want to do that: just create yourself a normal Thread using the Thread
Class
精彩评论