RunWorkerCompletedEventArgs クラス

定義

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
継承
RunWorkerCompletedEventArgs

RunWorkerCompletedEventArgs の使用方法を次のコード例に示します。The following code example illustrates the use of RunWorkerCompletedEventArgs. この例は、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

注釈

非同期操作にイベントベースの非同期パターンを使用する場合、Windows フォームフォームまたはコントロールは、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. さらに、メソッドは、BackgroundWorker.DoWork イベントを非同期に発生させ、DoWorkEventArgs インスタンスに渡します。The method in turn raises the BackgroundWorker.DoWork event asynchronously and passes it a DoWorkEventArgs instance. 非同期操作が値を返す場合は、通常、BackgroundWorker.DoWork イベントハンドラーによって DoWorkEventArgs.Result プロパティに割り当てられます。If the asynchronous operation returns a value, the BackgroundWorker.DoWork event handler typically assigns it to the DoWorkEventArgs.Result property. 非同期操作が完了すると、BackgroundWorker.RunWorkerCompleted イベントが発生し、操作の状態 (取り消されたか、エラーが発生したか、正常に完了したか) に関する情報を含む RunWorkerCompletedEventArgs インスタンスが渡されます。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). 正常に完了した場合、その Result プロパティには、非同期操作によって返され、以前に 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.

注意

このクラスに適用される HostProtectionAttribute 属性には、次の Resources プロパティ値があります: SharedStateThe HostProtectionAttribute attribute applied to this class has the following Resources property value: SharedState. HostProtectionAttribute は、デスクトップ アプリケーション (通常、アイコンのダブルクリック、コマンドの入力、またはブラウザーへの URL の入力により起動されます) には影響しません。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). 詳細については、「HostProtectionAttribute クラス」または「 SQL Server プログラミングとホスト保護の属性」を参照してください。For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

コンストラクター

RunWorkerCompletedEventArgs(Object, Exception, Boolean)

RunWorkerCompletedEventArgs クラスの新しいインスタンスを初期化します。Initializes a new instance of the RunWorkerCompletedEventArgs class.

プロパティ

Cancelled

非同期操作がキャンセルされたかどうかを示す値を取得します。Gets a value indicating whether an asynchronous operation has been canceled.

(継承元 AsyncCompletedEventArgs)
Error

非同期操作中に発生したエラーを示す値を取得します。Gets a value indicating which error occurred during an asynchronous operation.

(継承元 AsyncCompletedEventArgs)
Result

非同期操作の結果を表す値を取得します。Gets a value that represents the result of an asynchronous operation.

UserState

ユーザーの状態を表す値を取得します。Gets a value that represents the user state.

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判定します。Determines whether the specified object is equal to the current object.

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(継承元 Object)
RaiseExceptionIfNecessary()

非同期操作が失敗した場合は、ユーザー指定の例外を発生させます。Raises a user-supplied exception if an asynchronous operation failed.

(継承元 AsyncCompletedEventArgs)
ToString()

現在のオブジェクトを表す string を返します。Returns a string that represents the current object.

(継承元 Object)

適用対象

こちらもご覧ください