Occurs when RunWorkerAsync is called.
Assembly: System (in System.dll)
This event is raised when you call the RunWorkerAsync method. This is where you start the operation that performs the potentially time-consuming work.
Your code in the CancellationPending property value and abort the operation if it is true. When this occurs, you can set the Cancel flag of System.ComponentModel.DoWorkEventArgs to true, and the Cancelled flag of System.ComponentModel.RunWorkerCompletedEventArgs in your RunWorkerCompleted event handler will be set to true.event handler should periodically check the
Be aware that your code in the CancellationPending being set to true. In this case, the Cancelled flag of System.ComponentModel.RunWorkerCompletedEventArgs in your RunWorkerCompleted event handler will not be set to true, even though a cancellation request was made. This situation is called a race condition and is a common concern in multithreaded programming. For more information about multithreading design issues, see Managed Threading Best Practices.event handler may finish its work as a cancellation request is being made, and your polling loop may miss
If your operation produces a result, you can assign the result to the DoWorkEventArgs.Result property. This will be available to the RunWorkerCompleted event handler in the RunWorkerCompletedEventArgs.Result property.
If the operation raises an exception that your code does not handle, the BackgroundWorker catches the exception and passes it into the RunWorkerCompleted event handler, where it is exposed as the Error property of System.ComponentModel.RunWorkerCompletedEventArgs. If you are running under the Visual Studio debugger, the debugger will break at the point in the event handler where the unhandled exception was raised. If you have more than one BackgroundWorker, you should not reference any of them directly, as this would couple your event handler to a specific instance of BackgroundWorker. Instead, you should access your BackgroundWorker by casting the sender parameter in your event handler.
You must be careful not to manipulate any user-interface objects in your BackgroundWorker events.event handler. Instead, communicate to the user interface through the
For more information about handling events, see NIB: Consuming Events.
Available since 10
Available since 2.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0