DoWorkEventArgs Class

Definition

Provides data for the DoWork event handler.

C#
public class DoWorkEventArgs : EventArgs
C#
public class DoWorkEventArgs : System.ComponentModel.CancelEventArgs
Inheritance
DoWorkEventArgs
Inheritance
DoWorkEventArgs

Examples

The following code example demonstrates how to use the DoWorkEventArgs class to handle the DoWork event. For a full code listing, see How to: Run an Operation in the Background.

C#
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;
    }
}

Constructors

DoWorkEventArgs(Object)

Initializes a new instance of the DoWorkEventArgs class.

Properties

Argument

Gets a value that represents the argument of an asynchronous operation.

Cancel
Cancel

Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
Result

Gets or sets a value that represents the result of an asynchronous operation.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

See also