DoWorkEventArgs Class

Definition

Fornisce i dati per il gestore eventi DoWork.Provides data for the DoWork event handler.

public ref class DoWorkEventArgs : EventArgs
public ref class DoWorkEventArgs : System::ComponentModel::CancelEventArgs
public class DoWorkEventArgs : EventArgs
public class DoWorkEventArgs : System.ComponentModel.CancelEventArgs
type DoWorkEventArgs = class
    inherit EventArgs
type DoWorkEventArgs = class
    inherit CancelEventArgs
Public Class DoWorkEventArgs
Inherits EventArgs
Public Class DoWorkEventArgs
Inherits CancelEventArgs
Inheritance
DoWorkEventArgs
Inheritance
DoWorkEventArgs

Examples

Nell'esempio di codice riportato di seguito viene illustrato come utilizzare la classe DoWorkEventArgs per gestire l'evento DoWork.The following code example demonstrates how to use the DoWorkEventArgs class to handle the DoWork event. Per un listato di codice completo, vedere procedura: eseguire un'operazione in background.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;
    }
}
Private Sub backgroundWorker1_DoWork( _
sender As Object, e As DoWorkEventArgs) _
Handles backgroundWorker1.DoWork

   ' Do not access the form's BackgroundWorker reference directly.
   ' Instead, use the reference provided by the sender parameter.
   Dim bw As BackgroundWorker = CType( sender, BackgroundWorker )
   
   ' Extract the argument.
   Dim arg As Integer = Fix(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 Then
      e.Cancel = True
   End If

End Sub   

Constructors

DoWorkEventArgs(Object)

Inizializza una nuova istanza della classe DoWorkEventArgs.Initializes a new instance of the DoWorkEventArgs class.

Properties

Argument

Ottiene un valore che rappresenta l'argomento di un'operazione asincrona.Gets a value that represents the argument of an asynchronous operation.

Cancel
Cancel

Ottiene o imposta un valore che indica se l'evento debba essere annullato.Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
Result

Ottiene o imposta un valore che rappresenta il risultato di un'operazione asincrona.Gets or sets a value that represents the result of an asynchronous operation.

Methods

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also