RunWorkerCompletedEventArgs RunWorkerCompletedEventArgs RunWorkerCompletedEventArgs RunWorkerCompletedEventArgs Class

Définition

Fournit des données pour l’événement 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
Héritage
RunWorkerCompletedEventArgsRunWorkerCompletedEventArgsRunWorkerCompletedEventArgsRunWorkerCompletedEventArgs

Exemples

L’exemple de code suivant illustre l’utilisation de RunWorkerCompletedEventArgs.The following code example illustrates the use of RunWorkerCompletedEventArgs. Cet exemple fait partie d’un exemple plus large pour BackgroundWorker la classe.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

Remarques

Quand vous utilisez le modèle asynchrone basé sur les événements pour les opérations asynchrones, un formulaire ou un contrôle Windows Forms lance une opération BackgroundWorker.RunWorkerAsync asynchrone en appelant la méthode.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. La méthode déclenche à son tour BackgroundWorker.DoWork l’événement de manière asynchrone et lui DoWorkEventArgs passe une instance.The method in turn raises the BackgroundWorker.DoWork event asynchronously and passes it a DoWorkEventArgs instance. Si l’opération asynchrone retourne une valeur, le BackgroundWorker.DoWork gestionnaire d’événements l’assigne généralement à DoWorkEventArgs.Result la propriété.If the asynchronous operation returns a value, the BackgroundWorker.DoWork event handler typically assigns it to the DoWorkEventArgs.Result property. Lorsque l’opération asynchrone se termine, BackgroundWorker.RunWorkerCompleted l’événement est déclenché et reçoit une RunWorkerCompletedEventArgs instance qui contient des informations sur l’état de l’opération (qu’elle ait été annulée, défaillante ou correctement terminée).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 elle s’est terminée avec Result succès, sa propriété contient la valeur retournée par l’opération asynchrone et DoWorkEventArgs.Result précédemment assignée à la propriété.If it completed successfully, its Result property contains the value returned by the asynchronous operation and previously assigned to the DoWorkEventArgs.Result property.

Notes

L' HostProtectionAttribute attribut appliqué à cette classe a la valeur Resources de propriété suivante SharedState:.The HostProtectionAttribute attribute applied to this class has the following Resources property value: SharedState. HostProtectionAttribute n'affecte pas les applications bureautiques (qui sont généralement démarrées en double-cliquant sur une icône, en tapant une commande ou en entrant une URL dans un navigateur).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). Pour plus d’informations, consultez HostProtectionAttribute la classe ou SQL Server attributs de programmation et de protection de l’hôte.For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

Constructeurs

RunWorkerCompletedEventArgs(Object, Exception, Boolean) RunWorkerCompletedEventArgs(Object, Exception, Boolean) RunWorkerCompletedEventArgs(Object, Exception, Boolean) RunWorkerCompletedEventArgs(Object, Exception, Boolean)

Initialise une nouvelle instance de la classe RunWorkerCompletedEventArgs.Initializes a new instance of the RunWorkerCompletedEventArgs class.

Propriétés

Cancelled Cancelled Cancelled Cancelled

Obtient une valeur qui indique si une opération asynchrone a été annulée.Gets a value indicating whether an asynchronous operation has been canceled.

(Inherited from AsyncCompletedEventArgs)
Error Error Error Error

Obtient une valeur qui indique quelle erreur s'est produite pendant une opération asynchrone.Gets a value indicating which error occurred during an asynchronous operation.

(Inherited from AsyncCompletedEventArgs)
Result Result Result Result

Obtient une valeur qui représente le résultat d'une opération asynchrone.Gets a value that represents the result of an asynchronous operation.

UserState UserState UserState UserState

Obtient une valeur qui représente l'état d'utilisateur.Gets a value that represents the user state.

Méthodes

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Détermine si l'objet spécifié est identique à l'objet actuel.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fait office de fonction de hachage par défaut.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtient le Type de l'instance actuelle.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crée une copie superficielle de l'objet Object actuel.Creates a shallow copy of the current Object.

(Inherited from Object)
RaiseExceptionIfNecessary() RaiseExceptionIfNecessary() RaiseExceptionIfNecessary() RaiseExceptionIfNecessary()

Lève une exception fournie par l'utilisateur en cas d'échec d'une opération asynchrone.Raises a user-supplied exception if an asynchronous operation failed.

(Inherited from AsyncCompletedEventArgs)
ToString() ToString() ToString() ToString()

Retourne une chaîne qui représente l'objet actuel.Returns a string that represents the current object.

(Inherited from Object)

S’applique à

Voir aussi