DoWorkEventHandler Delegate
.NET Framework (current version)
Represents the method that will handle the DoWork event. This class cannot be inherited.
Assembly: System (in System.dll)
[HostProtectionAttribute(SecurityAction.LinkDemand, SharedState = true)] public delegate void DoWorkEventHandler( object sender, DoWorkEventArgs e )
Parameters
- sender
-
Type:
System.Object
The source of the event.
- e
-
Type:
System.ComponentModel.DoWorkEventArgs
A DoWorkEventArgs that contains the event data.
When you create a DoWorkEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event-handler method is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see NIB: Events and Delegates.
The following code example demonstrates how to use the DoWorkEventHandler delegate to handle the DoWork event. For a full code listing, see How to: Run an Operation in the Background.
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { // Do not access the form's BackgroundWorker reference directly. // Instead, use the reference provided by the sender parameter. BackgroundWorker bw = sender as BackgroundWorker; // Extract the argument. int arg = (int)e.Argument; // Start the time-consuming operation. e.Result = TimeConsumingOperation(bw, arg); // If the operation was canceled by the user, // set the DoWorkEventArgs.Cancel property to true. if (bw.CancellationPending) { e.Cancel = true; } }
Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 10
.NET Framework
Available since 2.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Show: