A simple Twitter client to demonstrate BackgroundWorker

5 04 2008

We have always had problems when we want to execute some operation that might take long time in a separate thread and at the same time updating UI components.

With BackgroundWorker class, we can simplify this process and makes it very simple for us to do asynchronous operations.

We initialize the BackgroundWorker and register for their events and run it asynchronously. So, when those events like WorkCompleted, ProgressChanged occurs, you are taken to your callback which is in the thread that started the BackgroundWorker.

BackgroundWorker LoginWorker = new BackgroundWorker();

LoginWorker.DoWork += new DoWorkEventHandler(worker_DoWork);

LoginWorker.RunWorkerCompleted +=new

RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

LoginWorker.WorkerSupportsCancellation = true;

I have developed a small (very) basic Twitter client to demonstrate the BackgroundWorker class

You can download the sample here

Advertisements