RunWorkerCompletedEventArgs Clase

Definición

Proporciona datos para el evento MethodNameCompleted.Provides data for the MethodNameCompleted event.

public ref class RunWorkerCompletedEventArgs : System::ComponentModel::AsyncCompletedEventArgs
public class RunWorkerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
type RunWorkerCompletedEventArgs = class
    inherit AsyncCompletedEventArgs
Public Class RunWorkerCompletedEventArgs
Inherits AsyncCompletedEventArgs
Herencia
RunWorkerCompletedEventArgs

Ejemplos

En el siguiente ejemplo de código, se muestra el uso de RunWorkerCompletedEventArgs.The following code example illustrates the use of RunWorkerCompletedEventArgs. Este ejemplo forma parte de un ejemplo más grande de la clase BackgroundWorker.This example is part of a larger sample for the BackgroundWorker class.

// This event handler deals with the results of the
// background operation.
void backgroundWorker1_RunWorkerCompleted( Object^ /*sender*/, RunWorkerCompletedEventArgs^ e )
{
   // First, handle the case where an exception was thrown.
   if ( e->Error != nullptr )
   {
      MessageBox::Show( e->Error->Message );
   }
   else
   if ( e->Cancelled )
   {
      // Next, handle the case where the user cancelled 
      // the operation.
      // Note that due to a race condition in 
      // the DoWork event handler, the Cancelled
      // flag may not have been set, even though
      // CancelAsync was called.
      resultLabel->Text = "Cancelled";
   }
   else
   {
      // Finally, handle the case where the operation 
      // succeeded.
      resultLabel->Text = e->Result->ToString();
   }

   // Enable the UpDown control.
   this->numericUpDown1->Enabled = true;

   // Enable the Start button.
   startAsyncButton->Enabled = true;

   // Disable the Cancel button.
   cancelAsyncButton->Enabled = false;
}
// This event handler deals with the results of the
// background operation.
private void backgroundWorker1_RunWorkerCompleted(
    object sender, RunWorkerCompletedEventArgs e)
{
    // First, handle the case where an exception was thrown.
    if (e.Error != null)
    {
        MessageBox.Show(e.Error.Message);
    }
    else if (e.Cancelled)
    {
        // Next, handle the case where the user canceled 
        // the operation.
        // Note that due to a race condition in 
        // the DoWork event handler, the Cancelled
        // flag may not have been set, even though
        // CancelAsync was called.
        resultLabel.Text = "Canceled";
    }
    else
    {
        // Finally, handle the case where the operation 
        // succeeded.
        resultLabel.Text = e.Result.ToString();
    }

    // Enable the UpDown control.
    this.numericUpDown1.Enabled = true;

    // Enable the Start button.
    startAsyncButton.Enabled = true;

    // Disable the Cancel button.
    cancelAsyncButton.Enabled = false;
}
' This event handler deals with the results of the
' background operation.
Private Sub backgroundWorker1_RunWorkerCompleted( _
ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) _
Handles backgroundWorker1.RunWorkerCompleted

    ' First, handle the case where an exception was thrown.
    If (e.Error IsNot Nothing) Then
        MessageBox.Show(e.Error.Message)
    ElseIf e.Cancelled Then
        ' Next, handle the case where the user canceled the 
        ' operation.
        ' Note that due to a race condition in 
        ' the DoWork event handler, the Cancelled
        ' flag may not have been set, even though
        ' CancelAsync was called.
        resultLabel.Text = "Canceled"
    Else
        ' Finally, handle the case where the operation succeeded.
        resultLabel.Text = e.Result.ToString()
    End If

    ' Enable the UpDown control.
    Me.numericUpDown1.Enabled = True

    ' Enable the Start button.
    startAsyncButton.Enabled = True

    ' Disable the Cancel button.
    cancelAsyncButton.Enabled = False
End Sub

Comentarios

Al usar el modelo asincrónico basado en eventos para las operaciones asincrónicas, un Windows Forms formulario o control inicia una operación asincrónica llamando al método BackgroundWorker.RunWorkerAsync.When using the event-based asynchronous pattern for asynchronous operations, a Windows Forms form or control initiates an asynchronous operation by calling the BackgroundWorker.RunWorkerAsync method. A su vez, el método genera el evento BackgroundWorker.DoWork de forma asincrónica y lo pasa a una instancia de DoWorkEventArgs.The method in turn raises the BackgroundWorker.DoWork event asynchronously and passes it a DoWorkEventArgs instance. Si la operación asincrónica devuelve un valor, el controlador de eventos BackgroundWorker.DoWork lo asigna normalmente a la propiedad DoWorkEventArgs.Result.If the asynchronous operation returns a value, the BackgroundWorker.DoWork event handler typically assigns it to the DoWorkEventArgs.Result property. Cuando se completa la operación asincrónica, se genera el evento de BackgroundWorker.RunWorkerCompleted y se pasa una instancia de RunWorkerCompletedEventArgs que contiene información sobre el estado de la operación (ya sea cancelada, con errores o completada correctamente).When the asynchronous operation completes, the BackgroundWorker.RunWorkerCompleted event is raised and is passed a RunWorkerCompletedEventArgs instance that contains information about the status of the operation (whether it was cancelled, faulted, or completed successfully). Si se completó correctamente, su propiedad Result contiene el valor devuelto por la operación asincrónica y asignado previamente a la propiedad DoWorkEventArgs.Result.If it completed successfully, its Result property contains the value returned by the asynchronous operation and previously assigned to the DoWorkEventArgs.Result property.

Nota

El HostProtectionAttribute atributo aplicado a esta clase tiene el siguiente valor de propiedad Resources: SharedState.The HostProtectionAttribute attribute applied to this class has the following Resources property value: SharedState. El atributo HostProtectionAttribute no afecta a las aplicaciones de escritorio (que normalmente se inician haciendo doble clic en un icono, escribiendo un comando o introduciendo una dirección URL en el explorador).The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). Para obtener más información, vea la clase HostProtectionAttribute o SQL Server atributos de programación y protección del host.For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

Constructores

RunWorkerCompletedEventArgs(Object, Exception, Boolean)

Inicializa una nueva instancia de la clase RunWorkerCompletedEventArgs.Initializes a new instance of the RunWorkerCompletedEventArgs class.

Propiedades

Cancelled

Obtiene un valor que indica si se ha cancelado una operación asincrónica.Gets a value indicating whether an asynchronous operation has been canceled.

(Heredado de AsyncCompletedEventArgs)
Error

Obtiene un valor que indica el error que se produjo durante una operación asincrónica.Gets a value indicating which error occurred during an asynchronous operation.

(Heredado de AsyncCompletedEventArgs)
Result

Obtiene un valor que representa el resultado de una operación asincrónica.Gets a value that represents the result of an asynchronous operation.

UserState

Obtiene un valor que representa el estado del usuario.Gets a value that represents the user state.

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.Determines whether the specified object is equal to the current object.

(Heredado de Object)
GetHashCode()

Sirve como función hash predeterminada.Serves as the default hash function.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.Creates a shallow copy of the current Object.

(Heredado de Object)
RaiseExceptionIfNecessary()

Genera una excepción proporcionada por el usuario si se ha producido un error en una operación asincrónica.Raises a user-supplied exception if an asynchronous operation failed.

(Heredado de AsyncCompletedEventArgs)
ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Heredado de Object)

Se aplica a

Consulte también: