JL.
JL.

Reputation: 81292

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.

Upvotes: 0

Views: 534

Answers (1)

Matthieu
Matthieu

Reputation: 114

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

Upvotes: 1

Related Questions