BackgroundWorker.RunWorkerAsync BackgroundWorker.RunWorkerAsync BackgroundWorker.RunWorkerAsync BackgroundWorker.RunWorkerAsync Method

定義

バックグラウンド操作の実行を開始します。Starts execution of a background operation.

オーバーロード

RunWorkerAsync() RunWorkerAsync() RunWorkerAsync() RunWorkerAsync()

バックグラウンド操作の実行を開始します。Starts execution of a background operation.

RunWorkerAsync(Object) RunWorkerAsync(Object) RunWorkerAsync(Object) RunWorkerAsync(Object)

バックグラウンド操作の実行を開始します。Starts execution of a background operation.

RunWorkerAsync() RunWorkerAsync() RunWorkerAsync() RunWorkerAsync()

バックグラウンド操作の実行を開始します。Starts execution of a background operation.

public:
 void RunWorkerAsync();
public void RunWorkerAsync ();
member this.RunWorkerAsync : unit -> unit
Public Sub RunWorkerAsync ()

例外

次のコード例は、の使用を示します、RunWorkerAsync非同期操作を開始する方法。The following code example demonstrates the use of the RunWorkerAsync method to start an asynchronous operation. 説明されている例の一部である方法。バック グラウンドでファイルをダウンロードします。It is part of a larger example described in How to: Download a File in the Background.

private void downloadButton_Click(object sender, EventArgs e)
{
    // Start the download operation in the background.
    this.backgroundWorker1.RunWorkerAsync();

    // Disable the button for the duration of the download.
    this.downloadButton.Enabled = false;

    // Once you have started the background thread you 
    // can exit the handler and the application will 
    // wait until the RunWorkerCompleted event is raised.

    // Or if you want to do something else in the main thread,
    // such as update a progress bar, you can do so in a loop 
    // while checking IsBusy to see if the background task is
    // still running.

    while (this.backgroundWorker1.IsBusy)
    {
        progressBar1.Increment(1);
        // Keep UI messages moving, so the form remains 
        // responsive during the asynchronous operation.
        Application.DoEvents();
    }
}
Private Sub downloadButton_Click( _
    ByVal sender As Object, _
    ByVal e As EventArgs) _
    Handles downloadButton.Click

    ' Start the download operation in the background.
    Me.backgroundWorker1.RunWorkerAsync()

    ' Disable the button for the duration of the download.
    Me.downloadButton.Enabled = False

    ' Once you have started the background thread you 
    ' can exit the handler and the application will 
    ' wait until the RunWorkerCompleted event is raised.

    ' If you want to do something else in the main thread,
    ' such as update a progress bar, you can do so in a loop 
    ' while checking IsBusy to see if the background task is
    ' still running.
    While Me.backgroundWorker1.IsBusy
        progressBar1.Increment(1)
        ' Keep UI messages moving, so the form remains 
        ' responsive during the asynchronous operation.
        Application.DoEvents()
    End While
End Sub

注釈

RunWorkerAsyncメソッドが非同期的に実行されている操作を開始する要求を送信します。The RunWorkerAsync method submits a request to start the operation running asynchronously. 要求が処理されるときに、 DoWork 、さらに、バック グラウンド操作の実行を開始するイベントが発生します。When the request is serviced, the DoWork event is raised, which in turn starts execution of your background operation.

呼び出して、バック グラウンド操作が既に実行されている場合RunWorkerAsync再度発生させる、InvalidOperationExceptionします。If the background operation is already running, calling RunWorkerAsync again will raise an InvalidOperationException.

こちらもご覧ください

RunWorkerAsync(Object) RunWorkerAsync(Object) RunWorkerAsync(Object) RunWorkerAsync(Object)

バックグラウンド操作の実行を開始します。Starts execution of a background operation.

public:
 void RunWorkerAsync(System::Object ^ argument);
public void RunWorkerAsync (object argument);
member this.RunWorkerAsync : obj -> unit
Public Sub RunWorkerAsync (argument As Object)

パラメーター

argument
Object Object Object Object

DoWork イベント ハンドラーで実行されるバックグラウンド操作で使用するパラメーター。A parameter for use by the background operation to be executed in the DoWork event handler.

例外

次のコード例は、の使用を示します、RunWorkerAsync非同期操作を開始する方法。The following code example demonstrates the use of the RunWorkerAsync method to start an asynchronous operation. このコード例が示されている例の一部、BackgroundWorkerクラス。This code example is part of a larger example provided for the BackgroundWorker class.

// Start the asynchronous operation.
backgroundWorker1->RunWorkerAsync( numberToCompute );
// Start the asynchronous operation.
backgroundWorker1.RunWorkerAsync(numberToCompute);

' Start the asynchronous operation.
backgroundWorker1.RunWorkerAsync(numberToCompute)

注釈

RunWorkerAsyncメソッドが非同期的に実行されている操作を開始する要求を送信します。The RunWorkerAsync method submits a request to start the operation running asynchronously. 要求が処理されるときに、 DoWork 、さらに、バック グラウンド操作の実行を開始するイベントが発生します。When the request is serviced, the DoWork event is raised, which in turn starts execution of your background operation.

操作は、パラメーターを必要とする場合、としてを指定できます、argumentパラメーターRunWorkerAsyncします。If your operation requires a parameter, you can provide it as the argument parameter to RunWorkerAsync.

呼び出して、バック グラウンド操作が既に実行されている場合RunWorkerAsync再度発生させる、InvalidOperationExceptionします。If the background operation is already running, calling RunWorkerAsync again will raise an InvalidOperationException.

こちらもご覧ください

適用対象