BackgroundWorker.RunWorkerAsync Method ()
Assembly: System (in system.dll)
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. Me.backgroundWorker1.RunWorkerAsync() ' 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. Application.DoEvents() 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 EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.