RunWorkerCompletedEventArgs 클래스

정의

MethodNameCompleted 이벤트에 대한 데이터를 제공합니다.

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사용을 보여 줍니다. 이 예제는 클래스에 대한 더 큰 샘플의 BackgroundWorker 일부입니다.

// 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 Forms 폼 또는 컨트롤은 메서드를 호출 BackgroundWorker.RunWorkerAsync 하여 비동기 작업을 시작합니다. 메서드는 이벤트를 비동기적으로 발생 BackgroundWorker.DoWork 시키고 instance 전달합니다 DoWorkEventArgs . 비동기 작업에서 값을 BackgroundWorker.DoWork 반환하는 경우 이벤트 처리기는 일반적으로 속성에 DoWorkEventArgs.Result 할당합니다. 비동기 작업이 완료되면 BackgroundWorker.RunWorkerCompleted 이벤트가 발생하고 작업의 상태 대한 정보를 포함하는 instance 전달 RunWorkerCompletedEventArgs 됩니다(취소, 오류 또는 성공적으로 완료되었는지 여부). 성공적으로 완료되면 해당 Result 속성에는 비동기 작업에서 반환되고 이전에 속성에 할당된 값이 DoWorkEventArgs.Result 포함됩니다.

참고

합니다 HostProtectionAttribute 이 클래스에 적용 된 특성에는 다음과 같은 Resources 속성 값: SharedState합니다. HostProtectionAttribute는 대개 아이콘을 두 번 클릭하거나, 명령을 입력하거나, 브라우저에서 URL을 입력하여 시작되는 데스크톱 애플리케이션에 영향을 미치지 않습니다. 자세한 내용은 참조는 HostProtectionAttribute 클래스 또는 SQL Server 프로그래밍 및 호스트 보호 특성합니다.

생성자

RunWorkerCompletedEventArgs(Object, Exception, Boolean)

RunWorkerCompletedEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

Cancelled

비동기 작업이 취소되었는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 AsyncCompletedEventArgs)
Error

비동기 작업 중 발생한 오류를 나타내는 값을 가져옵니다.

(다음에서 상속됨 AsyncCompletedEventArgs)
Result

비동기 작업의 결과를 나타내는 값을 가져옵니다.

UserState

사용자 상태를 나타내는 값을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
RaiseExceptionIfNecessary()

비동기 작업에 실패한 경우 사용자가 제공한 예외를 발생시킵니다.

(다음에서 상속됨 AsyncCompletedEventArgs)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보