Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

BackgroundWorker.RunWorkerAsync Method ()

Starts execution of a background operation.

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

Public Sub RunWorkerAsync
Dim instance As BackgroundWorker

public void RunWorkerAsync ()
public function RunWorkerAsync ()
Not applicable.

Exception typeCondition


IsBusy is true.

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

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

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 Sub dowloadButton_Click( _
ByVal sender As Object, _
ByVal e As EventArgs) _
Handles dowloadButton.Click

    ' Start the download operation in the background.

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

    ' Wait for the BackgroundWorker to finish the download.
    While Me.backgroundWorker1.IsBusy
        ' Keep UI messages moving, so the form remains 
        ' responsive during the asynchronous operation.
    End While

    ' The download is done, so enable the button.
    Me.dowloadButton.Enabled = True
End Sub

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

© 2015 Microsoft