RunWorkerCompletedEventArgs クラス
アセンブリ: System (system.dll 内)
構文
イベントベースの非同期パターンの概要を実装するクラスを使用している場合、そのクラスは 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.EventArgs
System.ComponentModel.AsyncCompletedEventArgs
System.ComponentModel.RunWorkerCompletedEventArgs
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- RunWorkerCompletedEventArgs クラスのページへのリンク