When you implement a class according to the Event-based Asynchronous Pattern Overview, you may need to track the lifetime of each asynchronous operation invoked on an instance of your class. The AsyncOperation class provides ways to track and report the progress of an asynchronous task.
The following list identifies ways to use an AsyncOperation object:
To report progress and interim results to the client, call Post from your asynchronous worker code.
To indicate that an asynchronous task has completed, or to cancel a pending asynchronous task, call PostOperationCompleted.
Your class should get an AsyncOperation object for each asynchronous task by calling AsyncOperationManager..::.CreateOperation when each task starts. To allow the client to distinguish separate asynchronous tasks, AsyncOperationManager..::.CreateOperation takes a parameter for a unique client-provided token, which becomes the UserSuppliedState property. It can then be used by client code to identify the particular asynchronous task that is raising progress or completion events.
Notes to Inheritors:
Implementers must ensure the PostOperationCompleted and Post invocations are asynchronous, so that class library providers do not need to concern themselves with potential stack overflows if they assume asynchronous behavior in a particular application model that happens to be synchronous.
For more information about implementing asynchronous classes, see Implementing the Event-based Asynchronous Pattern.