DoWorkEventHandler 대리자

정의

DoWork 이벤트를 처리할 메서드를 나타냅니다. 이 클래스는 상속될 수 없습니다.

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

매개 변수

sender
Object

이벤트 소스입니다.

e
DoWorkEventArgs

이벤트 데이터를 포함하는 DoWorkEventArgs입니다.

예제

다음 코드 예제에서는 대리자를 사용 하 여 DoWorkEventHandler 이벤트를 처리 하는 방법을 보여 줍니다 DoWork . 전체 코드 목록은 방법: 백그라운드에서 작업 실행을 참조하세요.

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    // Do not access the form's BackgroundWorker reference directly.
    // Instead, use the reference provided by the sender parameter.
    BackgroundWorker bw = sender as BackgroundWorker;

    // Extract the argument.
    int arg = (int)e.Argument;

    // Start the time-consuming operation.
    e.Result = TimeConsumingOperation(bw, arg);

    // If the operation was canceled by the user, 
    // set the DoWorkEventArgs.Cancel property to true.
    if (bw.CancellationPending)
    {
        e.Cancel = true;
    }
}
Private Sub backgroundWorker1_DoWork( _
sender As Object, e As DoWorkEventArgs) _
Handles backgroundWorker1.DoWork

   ' Do not access the form's BackgroundWorker reference directly.
   ' Instead, use the reference provided by the sender parameter.
   Dim bw As BackgroundWorker = CType( sender, BackgroundWorker )
   
   ' Extract the argument.
   Dim arg As Integer = Fix(e.Argument)
   
   ' Start the time-consuming operation.
   e.Result = TimeConsumingOperation(bw, arg)
   
   ' If the operation was canceled by the user, 
   ' set the DoWorkEventArgs.Cancel property to true.
   If bw.CancellationPending Then
      e.Cancel = True
   End If

End Sub

설명

DoWorkEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거 하지 않는 한 이벤트 처리기 메서드는 이벤트가 발생할 때마다 호출 됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보