TaskCompletionSource<TResult> Class
Represents the producer side of a Task<TResult> unbound to a delegate, providing access to the consumer side through the Task property.
Assembly: mscorlib (in mscorlib.dll)
The TaskCompletionSource<TResult> type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | TaskCompletionSource<TResult>() | Creates a TaskCompletionSource<TResult>. |
![]() | TaskCompletionSource<TResult>(Object) | Creates a TaskCompletionSource<TResult> with the specified state. |
![]() | TaskCompletionSource<TResult>(TaskCreationOptions) | Creates a TaskCompletionSource<TResult> with the specified options. |
![]() | TaskCompletionSource<TResult>(Object, TaskCreationOptions) | Creates a TaskCompletionSource<TResult> with the specified state and options. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | SetCanceled | Transitions the underlying Task<TResult> into the Canceled state. |
![]() | SetException(IEnumerable<Exception>) | Transitions the underlying Task<TResult> into the Faulted state. |
![]() | SetException(Exception) | Transitions the underlying Task<TResult> into the Faulted state. |
![]() | SetResult | Transitions the underlying Task<TResult> into the RanToCompletion state. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | TrySetCanceled | Attempts to transition the underlying Task<TResult> into the Canceled state. |
![]() | TrySetException(IEnumerable<Exception>) | Attempts to transition the underlying Task<TResult> into the Faulted state. |
![]() | TrySetException(Exception) | Attempts to transition the underlying Task<TResult> into the Faulted state. |
![]() | TrySetResult | Attempts to transition the underlying Task<TResult> into the RanToCompletion state. |
In many scenarios, it is useful to enable a Task<TResult> to represent an external asynchronous operation. TaskCompletionSource<TResult> is provided for this purpose. It enables the creation of a task that can be handed out to consumers, and those consumers can use the members of the task as they would any other. However, unlike most tasks, the state of a task created by a TaskCompletionSource is controlled explicitly by the methods on TaskCompletionSource. This enables the completion of the external asynchronous operation to be propagated to the underlying Task. The separation also ensures that consumers are not able to transition the state without access to the corresponding TaskCompletionSource. For more information, see the entry The Nature of TaskCompletionSource<TResult> in the Parallel Programming with .NET blog.
The Parallel Extensions samples also contain examples of how to use TaskCompletionSource<TResult>.
Note |
|---|
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Synchronization | ExternalThreading. 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. |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
