Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BackgroundWorker RunWorkerCompletedEventArgs.Cancelled always false

I cancel my operation by calling the CancelAsync() method on the BackgroundWorker, and when execution falls into the event RunWorkerCompleted, property Cancelled on RunWorkerCompletedEventArgs is false.

Though, I couldn't quite figure out when or where I should set it to true, as found in the EventArgs property. So, how?

like image 654
Smur Avatar asked Jan 21 '11 11:01

Smur


1 Answers

From MSDN:

The Cancelled property of RunWorkerCompletedEventArgs indicates whether a cancellation request was processed by the background operation.

If your code in the DoWork event handler detects a cancellation request by checking the CancellationPending flag and setting the Cancel flag of DoWorkEventArgs to true, the Cancelled flag of RunWorkerCompletedEventArgs also will be set to true.

like image 106
stuartd Avatar answered Sep 21 '22 08:09

stuartd