TaskCompletionSource Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
public ref class TaskCompletionSource
public class TaskCompletionSource
type TaskCompletionSource = class
Public Class TaskCompletionSource
- Inheritance
-
TaskCompletionSource
Remarks
It is often the case that a Task is desired to represent another asynchronous operation.
TaskCompletionSource 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.
All members of TaskCompletionSource are thread-safe and may be used from multiple threads concurrently.
Constructors
TaskCompletionSource() |
Creates a TaskCompletionSource. |
TaskCompletionSource(Object, TaskCreationOptions) |
Creates a TaskCompletionSource with the specified state and options. |
TaskCompletionSource(Object) |
Creates a TaskCompletionSource with the specified state. |
TaskCompletionSource(TaskCreationOptions) |
Creates a TaskCompletionSource with the specified options. |
Properties
Task |
Gets the Task created by this TaskCompletionSource. |
Methods
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) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
SetCanceled() | |
SetCanceled(CancellationToken) |
Transitions the underlying Task into the Canceled state using the specified token. |
SetException(Exception) | |
SetException(IEnumerable<Exception>) | |
SetFromTask(Task) |
Transitions the underlying Task<TResult> into the same completion state as the specified |
SetResult() |
Transitions the underlying Task into the RanToCompletion state. |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |
TrySetCanceled() |
Attempts to transition the underlying Task into the Canceled state. |
TrySetCanceled(CancellationToken) |
Attempts to transition the underlying Task into the Canceled state. |
TrySetException(Exception) |
Attempts to transition the underlying Task into the Faulted state. |
TrySetException(IEnumerable<Exception>) |
Attempts to transition the underlying Task into the Faulted state. |
TrySetFromTask(Task) |
Attempts to transition the underlying Task<TResult> into the same completion state as the specified |
TrySetResult() |
Attempts to transition the underlying Task into the RanToCompletion state. |