BackgroundWorker.RunWorkerAsync Methode

Definition

Startet die Ausführung eines Hintergrundvorgangs.

Überlädt

Name Beschreibung
RunWorkerAsync()

Startet die Ausführung eines Hintergrundvorgangs.

RunWorkerAsync(Object)

Startet die Ausführung eines Hintergrundvorgangs.

RunWorkerAsync()

Quelle:
BackgroundWorker.cs
Quelle:
BackgroundWorker.cs
Quelle:
BackgroundWorker.cs
Quelle:
BackgroundWorker.cs
Quelle:
BackgroundWorker.cs

Startet die Ausführung eines Hintergrundvorgangs.

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

Ausnahmen

Beispiele

Im folgenden Codebeispiel wird die Verwendung der RunWorkerAsync Methode zum Starten eines asynchronen Vorgangs veranschaulicht. Sie ist Teil eines größeren Beispiels, das unter How to: Download a File in the Background beschrieben wird.

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

    // Disable the button for the duration of the download.
    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 (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

Hinweise

Die RunWorkerAsync Methode sendet eine Anforderung, um den asynchron ausgeführten Vorgang zu starten. Wenn die Anforderung gewartet wird, wird das DoWork Ereignis ausgelöst, wodurch wiederum die Ausführung des Hintergrundvorgangs gestartet wird.

Wenn der Hintergrundvorgang bereits ausgeführt wird, löst der Aufruf RunWorkerAsync erneut eine InvalidOperationException.

Weitere Informationen

Gilt für:

RunWorkerAsync(Object)

Quelle:
BackgroundWorker.cs
Quelle:
BackgroundWorker.cs
Quelle:
BackgroundWorker.cs
Quelle:
BackgroundWorker.cs
Quelle:
BackgroundWorker.cs

Startet die Ausführung eines Hintergrundvorgangs.

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

Parameter

argument
Object

Ein Parameter für die Verwendung durch den Hintergrundvorgang, der DoWork im Ereignishandler ausgeführt werden soll.

Ausnahmen

Beispiele

Im folgenden Codebeispiel wird die Verwendung der RunWorkerAsync Methode zum Starten eines asynchronen Vorgangs veranschaulicht. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die BackgroundWorker Klasse bereitgestellt wird.

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

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

Hinweise

Die RunWorkerAsync Methode sendet eine Anforderung, um den asynchron ausgeführten Vorgang zu starten. Wenn die Anforderung gewartet wird, wird das DoWork Ereignis ausgelöst, wodurch wiederum die Ausführung des Hintergrundvorgangs gestartet wird.

Wenn für den Vorgang ein Parameter erforderlich ist, können Sie ihn als argument Parameter angeben.RunWorkerAsync

Wenn der Hintergrundvorgang bereits ausgeführt wird, löst der Aufruf RunWorkerAsync erneut eine InvalidOperationException.

Weitere Informationen

Gilt für: