public override void Cancel() { if (_worker != null) { if (_worker.IsBusy) { _worker.CancelAsync(); // Wait for the ConsoleWorker to finish the download. while (_worker.IsBusy) { // Keep UI messages moving, so the form remains // responsive during the asynchronous operation. MainApplication.DoEvents(); } } } }
public void Cancel() { btnCancel.IsEnabled = false; if (_worker != null) { if (_worker.IsBusy) { _worker.CancelAsync(); // Wait for the BackgroundWorker to finish the download. while (_worker.IsBusy) { // Keep UI messages moving, so the form remains // responsive during the asynchronous operation. MainApplication.DoEvents(); } } } }