RunWorkerCompletedEventHandler RunWorkerCompletedEventHandler RunWorkerCompletedEventHandler RunWorkerCompletedEventHandler Delegate

정의

RunWorkerCompleted 클래스의 BackgroundWorker 이벤트를 처리할 메서드를 나타냅니다.Represents the method that will handle the RunWorkerCompleted event of a BackgroundWorker class.

public delegate void RunWorkerCompletedEventHandler(System::Object ^ sender, RunWorkerCompletedEventArgs ^ e);
public delegate void RunWorkerCompletedEventHandler(object sender, RunWorkerCompletedEventArgs e);
type RunWorkerCompletedEventHandler = delegate of obj * RunWorkerCompletedEventArgs -> unit
Public Delegate Sub RunWorkerCompletedEventHandler(sender As Object, e As RunWorkerCompletedEventArgs)

매개 변수

sender
Object Object Object Object

이벤트 소스입니다.The source of the event.

상속
RunWorkerCompletedEventHandlerRunWorkerCompletedEventHandlerRunWorkerCompletedEventHandlerRunWorkerCompletedEventHandler

예제

다음 코드 예제에 대 한 처리기로 사용할 수 있는 메서드를 보여 줍니다. RunWorkerCompletedEventHandler합니다.The following code example shows a method that can be used as a handler for RunWorkerCompletedEventHandler. 이 예제는에 대 한 더 큰 샘플의 일부를 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 'backgroundWorker1_RunWorkerCompleted

설명

만들 때는 RunWorkerCompletedEventHandler 대리자를 이벤트를 처리할 메서드를 식별 합니다.When you create a RunWorkerCompletedEventHandler delegate, you identify a method to handle the event. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다.To associate the event with your event handler, add an instance of the delegate to the event. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다.The event handler is called whenever the event occurs, unless you remove the delegate. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.For more information about event handler delegates, see Handling and Raising Events.

Extension Methods

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

지정 된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.Gets an object that represents the method represented by the specified delegate.

적용 대상