The Event-Based Asynchronous Pattern
Some components allow you to perform asynchronous work without
having to worry about the details of the dispatcher. This is possible
thanks to the event-based asynchronous
pattern, which was introduced in NET 2.0. Components that
implement this pattern manage the necessary thread switching for you.
They do so using the AsyncOperationManager family of
classes,[129] which abstract away the details of UI threading
requirements, supporting both Windows Forms and WPF through a common
API. This means that classes designed for use in Windows Forms
applications will also work correctly in WPF applications.
The event-based asynchronous pattern is fairly simple. A class
will provide one or more methods whose names end in Async. For example, the WebClient class in the System.Net namespace offers an UploadFileAsync method. Each asynchronous
method has a corresponding event to signal completion—UploadFileCompleted, in this case. There may
optionally be other events to indicate partial progress, such as the
UploadProgressChanged event offered
by WebClient. The crucial feature of
the event-based asynchronous pattern is that the events are raised on
the UI thread. For example, if you call UploadFileAsync from the UI thread of a WPF
application, the object will raise the UploadFileCompleted event on the same
thread.
Not all components offer this pattern. Fortunately, .NET provides an implementation of the pattern that you can use to wrap slow, synchronous code: ...