TaskCompletionSource<TResult> Class
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
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 the Object 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 [e7b31170-a156-433f-9f26-b1fc7cd1776f.]
The Parallel Extensions samples also contain examples of how to use TaskCompletionSource<TResult>.


