Manage a background process by using the BackgroundWorker component.
- Run a background process by using the BackgroundWorker component.
- Announce the completion of a background process by using the BackgroundWorker component.
- Cancel a background process by using the BackgroundWorker component.
- Report the progress of a background process by using the BackgroundWorker component.
- Request the status of a background process by using the BackgroundWorker component.
The BackgroundWorker component is intended to make multi threading easier. Ben Lovell has a good post that explains how to use it.
The code that will run in the background is placed in the DoWork event. Remember that it is operating in a different thread than the UI, so if you want to touch any of the UI, you need to use BeginInvoke or Invoke.
To annouce the completion of a background process, you let the DoWork event finish. That will fire the RunWorkerCompleted event.
To cancel a background process, you call the CancelAsync method. In the DoWork event, you should constantly be checking the CancellationPending property, it doesn't automatically cancel itself.
To report progress, call the ReportProgress method, while in the DoWork event.
There's no obvious way to "request" the status of a background process. There is a ProgressChanged event that you can hook into.
Next up-> Clickonce