Instead of using Thread class for asynchronous operations we can use the BackgroundWorker class in .Net.
This class gives you much flexibility over Thread class. The important events we should use are
DoWork and RunWorkerCompleted. The DoWork event should be handled to process the core work of thread.
The RunWorkerCompleted event is called when the DoWork method is processed.
private void CodeSample()
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
private object value;
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
if (value != null)
private void worker_DoWork(object sender, DoWorkEventArgs e)
// Get value from a web service
value = GetValueFromWebService();