I need to make sure a BackgroundWoker isn’t busy before being called, so I check IsBusy and call CancelAsync if it is:
if (bgWorker.IsBusy)
bgWorker.CancelAsync();
But if IsBusy is true, an InvalidOperationException exception occurs in CancelAsync() saying “BackgroundWorker does not support cancellation.”
The documentation makes usage seem pretty straightforward, so what am I doing wrong? How can I cancel the job?
You’ll need to set the BackgroundWorker.WorkerSupportsCancellation Property to true.