Partager via


BackgroundWorker.RunWorkerAsync Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Starts running a background operation.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

Syntax

'Declaration
Public Sub RunWorkerAsync
public void RunWorkerAsync()

Exceptions

Exception Condition
InvalidOperationException

IsBusy is true.

Remarks

The RunWorkerAsync method submits a request to start the operation running asynchronously. When the request is processed, the DoWork event is raised, which in turn starts running your background operation.

If the background operation is already running, calling RunWorkerAsync again will raise an InvalidOperationException.

Examples

The following code example demonstrates the use of the RunWorkerAsync method to start a background operation. To view the complete code for this sample, see How to: Use a Background Worker.

Private Sub buttonStart_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    If Not bw.IsBusy = True Then
        bw.RunWorkerAsync()
    End If
End Sub
private void buttonStart_Click(object sender, RoutedEventArgs e)
{
    if (bw.IsBusy != true)
    {
        bw.RunWorkerAsync();
    }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.