Smur
Smur

Reputation: 3113

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?

Upvotes: 13

Views: 3699

Answers (1)

stuartd
stuartd

Reputation: 73253

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.

Upvotes: 19

Related Questions