The BackGroundWorker class makes it easy to execute an operation on a seperate, dedicated thread. In the past, creating new threads for simple background operations could prove to be quite troublesome. The BackGroundWorker class makes it easy.
To set up a BackGroundWorker simply add an event handler for the DoWork event. You can put your long, time-consuming operations inside that event. When you are ready to start the operation, simply call the RunWorkerAsync method. The ProgressChanged event can be used to notify your application of any progress that has occurred. Lastly, the RunWorkerCompleted method will fire when the operation has completed.
// Set up the BackgroundWorker object by
// attaching event handlers
protected void InitializeBackgoundWorker()
// launch the aync process on a button click event
protected void Button_Click(System.Object sender, System.EventArgs e)
// start the async process
// perform the long operation
protected void backgroundWorker1_DoWork(object sender,
// do something
// work completed event
protected void backgroundWorker1_RunWorkerCompleted(
object sender, RunWorkerCompletedEventArgs e)
// display completed message
For more information, take a look at: