Step-by-Step Instructions for using the BackgroundWorker

The purpose of the Background Worker component is to allow you to easily perform a background task in a Windows Forms application.  Because Windows Forms have thread affinity, you can only touch controls on the main UI thread.  The Background Worker enables you to cleanly run tasks on the appropriate thread without having to jump through too many hoops.  However, the API can seem confusing at times.  So here is a simple set of step-by-step instructions for using the component.
 

1.      Set the following BW property to True (design-time):
WorkerReportsProgress

2.      Create DoWork event handler (design-time).

3.      Create ProgressChanged event handler (design-time).

4.      Create RunWorkerCompleted event handler (design-time).

5.      Call BW’s RunWorkerAsync method to fire DoWork event.

6.      To be able to cancel an async operation, perform the following steps:

That’s all there is to it!  Now all you have to do is practice.  :-)

Check out this working demo with sample code.