Let\'s say I have a background worker like this:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { while(true)
Use the CancelAsync method.
backgroundworker1.CancelAsync();
In your loop inside the worker thread.
if (backgroundWorker.CancellationPending) return;
This doesn't happen immediately.