RunWorkerCompletedEventArgsとは? わかりやすく解説

RunWorkerCompletedEventArgs クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

MethodName Completed イベントのデータを提供します。

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文構文

Public Class RunWorkerCompletedEventArgs
    Inherits AsyncCompletedEventArgs
Dim instance As RunWorkerCompletedEventArgs
public class RunWorkerCompletedEventArgs :
 AsyncCompletedEventArgs
public ref class RunWorkerCompletedEventArgs
 : public AsyncCompletedEventArgs
public class RunWorkerCompletedEventArgs extends
 AsyncCompletedEventArgs
public class RunWorkerCompletedEventArgs extends
 AsyncCompletedEventArgs
解説解説

イベントベースの非同期パターンの概要を実装するクラスを使用している場合、そのクラスは MethodNameCompleted イベントを提供します。MethodName は、メソッド名の最初の部分を表すプレースホルダです。BackgroundWorker.OnRunWorkerCompleted は、このようなメソッドの名前の例です。RunWorkerCompletedEventArgs デリゲートのインスタンスをイベントに追加すると、対応するイベント ハンドラの RunWorkerCompletedEventArgs パラメータに非同期操作の結果に関する情報を受け取ります。

メモメモ

このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、SharedState です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。

使用例使用例

RunWorkerCompletedEventArgs の使用方法を次のコード例に示します。このコード例は、BackgroundWorker クラスのトピックで取り上げているコード例の一部です。

' 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 Not (e.Error Is 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 'backgroundWorker1_RunWorkerCompleted
// 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.
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.get_Error() != null) {
    
        MessageBox.Show(e.get_Error().get_Message());
    }
    else {
    
        if (e.get_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.set_Text("Cancelled");
        }
        else {
        
            // Finally, handle the case where the operation 
            // succeeded.
            resultLabel.set_Text(e.get_Result().ToString());
        }
    }

    // Enable the UpDown control.
    this.numericUpDown1.set_Enabled(true);

    // Enable the Start button.
    startAsyncButton.set_Enabled(true);

    // Disable the Cancel button.
    cancelAsyncButton.set_Enabled(false);
} //backgroundWorker1_RunWorkerCompleted
継承階層継承階層
System.Object
   System.EventArgs
     System.ComponentModel.AsyncCompletedEventArgs
      System.ComponentModel.RunWorkerCompletedEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

RunWorkerCompletedEventArgs コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

RunWorkerCompletedEventArgs クラスの新しいインスタンスを初期化します。

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    result As Object, _
    error As Exception, _
    cancelled As Boolean _
)
Dim result As Object
Dim error As Exception
Dim cancelled As Boolean

Dim instance As New RunWorkerCompletedEventArgs(result,
 error, cancelled)
public RunWorkerCompletedEventArgs (
    Object result,
    Exception error,
    bool cancelled
)
public:
RunWorkerCompletedEventArgs (
    Object^ result, 
    Exception^ error, 
    bool cancelled
)
public RunWorkerCompletedEventArgs (
    Object result, 
    Exception error, 
    boolean cancelled
)
public function RunWorkerCompletedEventArgs
 (
    result : Object, 
    error : Exception, 
    cancelled : boolean
)

パラメータ

result

非同期操作の結果。

error

非同期操作中に発生したエラー。

cancelled

非同期操作がキャンセルされたかどうかを示す値。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

RunWorkerCompletedEventArgs プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Cancelled  非同期操作がキャンセルされたかどうかを示す値を取得します。 ( AsyncCompletedEventArgs から継承されます。)
パブリック プロパティ Error  非同期操作中に発生したエラーを示す値を取得します。 ( AsyncCompletedEventArgs から継承されます。)
パブリック プロパティ Result 非同期操作の結果を表す値を取得します。
パブリック プロパティ UserState ユーザーの状態を表す値を取得します。
参照参照

RunWorkerCompletedEventArgs メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

RunWorkerCompletedEventArgs メンバ

MethodName Completed イベントのデータを提供します。

RunWorkerCompletedEventArgs データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド RunWorkerCompletedEventArgs RunWorkerCompletedEventArgs クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Cancelled  非同期操作がキャンセルされたかどうかを示す値を取得します。(AsyncCompletedEventArgs から継承されます。)
パブリック プロパティ Error  非同期操作中に発生したエラーを示す値を取得します。(AsyncCompletedEventArgs から継承されます。)
パブリック プロパティ Result 非同期操作の結果を表す値を取得します。
パブリック プロパティ UserState ユーザーの状態を表す値を取得します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「RunWorkerCompletedEventArgs」の関連用語

RunWorkerCompletedEventArgsのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



RunWorkerCompletedEventArgsのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS