Tracks the lifetime of an asynchronous operation.
Assembly: System (in System.dll)
Thetype exposes the following members.
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|OperationCompleted||Ends the lifetime of an asynchronous operation.|
|Post||Invokes a delegate on the thread or context appropriate for the application model.|
|PostOperationCompleted||Ends the lifetime of an asynchronous operation.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
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 class provides ways to track and report the progress of an asynchronous task.
The following list identifies ways to use an 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 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.
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: SharedState. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.
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.
The following code example demonstrates using an object to track the lifetime of asynchronous operations. This code example is part of a larger example provided for the System.ComponentModel.AsyncOperationManager class.
For a full code listing, see How to: Implement a Component That Supports the Event-based Asynchronous Pattern. For a full code listing of a client form, see How to: Implement a Client of the Event-based Asynchronous Pattern.