RunWorkerCompletedEventArgs.Result 속성

정의

비동기 작업의 결과를 나타내는 값을 가져옵니다.Gets a value that represents the result of an asynchronous operation.

public:
 property System::Object ^ Result { System::Object ^ get(); };
public object Result { get; }
member this.Result : obj
Public ReadOnly Property Result As Object

속성 값

Object

비동기 작업의 결과를 나타내는 Object입니다.An Object representing the result of an asynchronous operation.

예외

Errornull가 아닙니다.Error is not null. InnerException 속성에는 Error에 대한 참조가 들어 있습니다.The InnerException property holds a reference to Error.

Cancelled이(가) true인 경우Cancelled is true.

예제

다음 코드 예제에서는 이벤트를 사용 하 여 RunWorkerCompleted 비동기 작업의 결과를 처리 하는 방법을 보여 줍니다.The following code example demonstrates the use of the RunWorkerCompleted event to handle the result of an asynchronous operation. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 BackgroundWorker 클래스입니다.This code example is part of a larger example provided 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

설명

RunWorkerCompleted이벤트 처리기는 Error 속성에 Cancelled 액세스 하기 전에 항상 및 속성을 확인 해야 합니다 Result .Your RunWorkerCompleted event handler should always check the Error and Cancelled properties before accessing the Result property. 예외가 발생 했거나 작업이 취소 된 경우 속성에 액세스 하면 Result 예외가 발생 합니다.If an exception was raised or if the operation was canceled, accessing the Result property raises an exception.

적용 대상

추가 정보