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)

指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。

適用対象

こちらもご覧ください