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.

操作にパラメーターが必要な場合は、パラメーターとしてargumentRunWorkerAsync渡すことができます。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.

こちらもご覧ください

適用対象