As I have seen today in Whidbey there are a lot of new components and controls for WinForms programming. A cool new component is the System.ComponentModel.BackgroundWorker component. With this component you can initialize a new worker thread and execute them async. [Klaus Aschenbrenner]
The BackgroundWorker has several other cool features:
BackgroundWorker.CancelAsync() and BackgroundWorker.CancellationPending - allow you to notify the worker thread that you want to cancel the job.
BackgroundWorker.ReportProgress() and BackgroundWorker.ProgressChanged - the worker thread can call ReportProgress() which fires the ProgressChanged event. This is handy for updating progress bars etc. The ProgressChanged event handler runs on the original thread not the worker thread.
BackgroundWorker.RunWorkerCompleted - this event is fired when the worker thread is finished. It reports the final status of the worker thread, any exceptions that were thrown, and any resulting data from the worker thread. The RunWorkerCompleted event handler also runs on the original thread.
Since the only code that runs on the worker thread is the DoWork event handler you only have to worry about thread safety there. Since the BackgroundWorker provides for progress reporting, returning results, canceling, catching exceptions, etc. you can focus on the business logic in the DoWork event handler.
The pattern that the BackgroundWorker defines is used throughout Whidbey. The new Web Service Proxy classes will use it so Web Service calls will be asynchronous by default. The new Asynchronous ADO.NET functionality uses the BackgroundWorker pattern too.