Task class

Represents an asynchronous operation. Each Task is a thin wrapper over Task and each call simply invokes the wrapped task. During testing, a Task is controlled by the runtime and systematically interleaved with other asynchronous operations to find bugs.

public class Task : IDisposable

Public Members

name description
static CompletedTask { get; } A Task that has completed successfully.
static Delay(…) Creates a Task that completes after a time delay. (4 methods)
static FromCanceled(…) Creates a Task that is completed due to cancellation with a specified cancellation token.
static FromException(…) Creates a Task that is completed with a specified exception.
static Run(…) Queues the specified work to run on the thread pool and returns a Task object that represents that work. A cancellation token allows the work to be cancelled. (4 methods)
static WhenAll(…) Creates a Task that will complete when all tasks in the specified array have completed. (2 methods)
Exception { get; } Gets the AggregateException that caused the task to end prematurely. If the task completed successfully or has not yet thrown any exceptions, this will return null.
Id { get; } The id of this task.
IsCanceled { get; } Value that indicates whether the task completed execution due to being canceled.
IsCompleted { get; } Value that indicates whether the task has completed.
IsFaulted { get; } Value that indicates whether the task completed due to an unhandled exception.
Status { get; } The status of this task.
UncontrolledTask { get; } The uncontrolled Task that is wrapped inside this controlled Task.
ConfigureAwait(…) Configures an awaiter used to await this task.
Dispose() Disposes the Task, releasing all of its unmanaged resources.
GetAwaiter() Gets an awaiter for this awaitable.
Wait() Waits for the task to complete execution.
Wait(…) Waits for the task to complete execution within a specified time interval. (4 methods)
static CurrentId { get; } Returns the id of the currently executing Task.
static ExploreContextSwitch() Injects a context switch point that can be systematically explored during testing.
static FromCanceled<TResult>(…) Creates a Task that is completed due to cancellation with a specified cancellation token.
static FromException<TResult>(…) Creates a Task that is completed with a specified exception.
static FromResult<TResult>(…) Creates a Task that is completed successfully with the specified result.
static Run<TResult>(…) Queues the specified work to run on the thread pool and returns a proxy for the Task returned by the function. (4 methods)
static WaitAll(…) Waits for all of the provided Task objects to complete execution. (5 methods)
static WaitAny(…) Waits for any of the provided Task objects to complete execution. (5 methods)
static WhenAll<TResult>(…) Creates a Task that will complete when all tasks in the specified array have completed. (2 methods)
static WhenAny(…) Creates a Task that will complete when any task in the specified array have completed. (2 methods)
static WhenAny<TResult>(…) Creates a Task that will complete when any task in the specified array have completed. (2 methods)
static Yield() Creates an awaitable that asynchronously yields back to the current context when awaited.

Protected Members

name description
virtual Dispose(…) Disposes the Task, releasing all of its unmanaged resources.

Remarks

See Programming model: asynchronous tasks for more information.

See Also