Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Threading.​Tasks.​Task
Assembly: System.Runtime
Inheritance: object → Task
Implemented Interfaces
Represents an asynchronous operation.
Properties
public
object
AsyncState
Gets the state object supplied when the <see cref="T:System.Threading.Tasks.Task" /> was created, or null if none was supplied.
public static
Task
CompletedTask
Gets a task that has already completed successfully.
public
TaskCreationOptions
CreationOptions
Gets the <see cref="T:System.Threading.Tasks.TaskCreationOptions" /> used to create this task.
public static
int?
CurrentId
Returns the ID of the currently executing <see cref="T:System.Threading.Tasks.Task" /> .
public
AggregateException
Exception
Gets the <see cref="T:System.AggregateException" /> that caused the <see cref="T:System.Threading.Tasks.Task" /> to end prematurely. If the <see cref="T:System.Threading.Tasks.Task" /> completed successfully or has not yet thrown any exceptions, this will return <see langword="null" /> .
public static
TaskFactory
Factory
Provides access to factory methods for creating and configuring <see cref="T:System.Threading.Tasks.Task" /> and <see cref="T:System.Threading.Tasks.Task`1" /> instances.
public
int
Id
Gets an ID for this <see cref="T:System.Threading.Tasks.Task" /> instance.
public
bool
IsCanceled
Gets whether this <see cref="T:System.Threading.Tasks.Task" /> instance has completed execution due to being canceled.
public
bool
IsCompleted
Gets a value that indicates whether the task has completed.
public
bool
IsCompletedSuccessfully
Gets whether the task ran to completion.
public
bool
IsFaulted
Gets whether the <see cref="T:System.Threading.Tasks.Task" /> completed due to an unhandled exception.
public
TaskStatus
Status
Gets the <see cref="T:System.Threading.Tasks.TaskStatus" /> of this task.
Methods
ConfigureAwait​(bool continueOnCapturedContext)
Configures an awaiter used to await this <see cref="T:System.Threading.Tasks.Task" /> .
Returns An object used to await this task.
continueOnCapturedContext
<see langword="true" /> to attempt to marshal the continuation back to the original context captured; otherwise, <see langword="false" /> .
ConfigureAwait​(ConfigureAwaitOptions options)
Configures an awaiter used to await this <see cref="T:System.Threading.Tasks.Task" /> .
Returns An object used to await this task.
options
Options used to configure how awaits on this task are performed.
public
Task
ContinueWith​(Action<​Task, object> continuationAction,
object state)
Creates a continuation that receives caller-supplied state information and executes when the target <see cref="T:System.Threading.Tasks.Task" /> completes.
Returns A new continuation task.
continuationAction
An action to run when the task completes. When run, the delegate is passed the completed task and a caller-supplied state object as arguments.
state
An object representing data to be used by the continuation action.
public
Task
ContinueWith​(Action<​Task, object> continuationAction,
object state,
CancellationToken cancellationToken)
Creates a continuation that receives caller-supplied state information and a cancellation token and that executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task" /> .
continuationAction
An action to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.
state
An object representing data to be used by the continuation action.
cancellationToken
The <see cref="T:System.Threading.CancellationToken" /> that will be assigned to the new continuation task.
public
Task
ContinueWith​(Action<​Task, object> continuationAction,
object state,
CancellationToken cancellationToken,
TaskContinuationOptions continuationOptions,
TaskScheduler scheduler)
Creates a continuation that receives caller-supplied state information and a cancellation token and that executes when the target <see cref="T:System.Threading.Tasks.Task" /> completes. The continuation executes based on a set of specified conditions and uses a specified scheduler.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task" /> .
continuationAction
An action to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.
state
An object representing data to be used by the continuation action.
cancellationToken
The <see cref="T:System.Threading.CancellationToken" /> that will be assigned to the new continuation task.
continuationOptions
Options for when the continuation is scheduled and how it behaves. This includes criteria, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled" /> , as well as execution options, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously" /> .
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> to associate with the continuation task and to use for its execution.
public
Task
ContinueWith​(Action<​Task, object> continuationAction,
object state,
TaskContinuationOptions continuationOptions)
Creates a continuation that receives caller-supplied state information and executes when the target <see cref="T:System.Threading.Tasks.Task" /> completes. The continuation executes based on a set of specified conditions.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task" /> .
continuationAction
An action to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.
state
An object representing data to be used by the continuation action.
continuationOptions
Options for when the continuation is scheduled and how it behaves. This includes criteria, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled" /> , as well as execution options, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously" /> .
public
Task
ContinueWith​(Action<​Task, object> continuationAction,
object state,
TaskScheduler scheduler)
Creates a continuation that receives caller-supplied state information and executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes. The continuation uses a specified scheduler.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task" /> .
continuationAction
An action to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.
state
An object representing data to be used by the continuation action.
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> to associate with the continuation task and to use for its execution.
public
Task
ContinueWith​(Action<​Task> continuationAction)
Creates a continuation that executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task" /> .
continuationAction
An action to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task as an argument.
public
Task
ContinueWith​(Action<​Task> continuationAction,
CancellationToken cancellationToken)
Creates a continuation that receives a cancellation token and executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task" /> .
continuationAction
An action to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task as an argument.
cancellationToken
The <see cref="P:System.Threading.Tasks.TaskFactory.CancellationToken" /> that will be assigned to the new continuation task.
public
Task
ContinueWith​(Action<​Task> continuationAction,
CancellationToken cancellationToken,
TaskContinuationOptions continuationOptions,
TaskScheduler scheduler)
Creates a continuation that executes when the target task competes according to the specified <see cref="T:System.Threading.Tasks.TaskContinuationOptions" /> . The continuation receives a cancellation token and uses a specified scheduler.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task" /> .
continuationAction
An action to run according to the specified <paramref name="continuationOptions" /> . When run, the delegate will be passed the completed task as an argument.
cancellationToken
The <see cref="P:System.Threading.Tasks.TaskFactory.CancellationToken" /> that will be assigned to the new continuation task.
continuationOptions
Options for when the continuation is scheduled and how it behaves. This includes criteria, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled" /> , as well as execution options, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously" /> .
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> to associate with the continuation task and to use for its execution.
public
Task
ContinueWith​(Action<​Task> continuationAction,
TaskContinuationOptions continuationOptions)
Creates a continuation that executes when the target task completes according to the specified <see cref="T:System.Threading.Tasks.TaskContinuationOptions" /> .
Returns A new continuation <see cref="T:System.Threading.Tasks.Task" /> .
continuationAction
An action to run according to the specified <paramref name="continuationOptions" /> . When run, the delegate will be passed the completed task as an argument.
continuationOptions
Options for when the continuation is scheduled and how it behaves. This includes criteria, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled" /> , as well as execution options, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously" /> .
public
Task
ContinueWith​(Action<​Task> continuationAction,
TaskScheduler scheduler)
Creates a continuation that executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes. The continuation uses a specified scheduler.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task" /> .
continuationAction
An action to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task as an argument.
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> to associate with the continuation task and to use for its execution.
public
Task<​TResult>
ContinueWith​(Func<​Task, object, TResult> continuationFunction,
object state)
Creates a continuation that receives caller-supplied state information and executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes and returns a value.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task`1" /> .
continuationFunction
A function to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.
state
An object representing data to be used by the continuation function.
public
Task<​TResult>
ContinueWith​(Func<​Task, object, TResult> continuationFunction,
object state,
CancellationToken cancellationToken)
Creates a continuation that executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes and returns a value. The continuation receives caller-supplied state information and a cancellation token.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task`1" /> .
continuationFunction
A function to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.
state
An object representing data to be used by the continuation function.
cancellationToken
The <see cref="T:System.Threading.CancellationToken" /> that will be assigned to the new continuation task.
public
Task<​TResult>
ContinueWith​(Func<​Task, object, TResult> continuationFunction,
object state,
CancellationToken cancellationToken,
TaskContinuationOptions continuationOptions,
TaskScheduler scheduler)
Creates a continuation that executes based on the specified task continuation options when the target <see cref="T:System.Threading.Tasks.Task" /> completes and returns a value. The continuation receives caller-supplied state information and a cancellation token and uses the specified scheduler.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task`1" /> .
continuationFunction
A function to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.
state
An object representing data to be used by the continuation function.
cancellationToken
The <see cref="T:System.Threading.CancellationToken" /> that will be assigned to the new continuation task.
continuationOptions
Options for when the continuation is scheduled and how it behaves. This includes criteria, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled" /> , as well as execution options, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously" /> .
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> to associate with the continuation task and to use for its execution.
public
Task<​TResult>
ContinueWith​(Func<​Task, object, TResult> continuationFunction,
object state,
TaskContinuationOptions continuationOptions)
Creates a continuation that executes based on the specified task continuation options when the target <see cref="T:System.Threading.Tasks.Task" /> completes. The continuation receives caller-supplied state information.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task`1" /> .
continuationFunction
A function to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.
state
An object representing data to be used by the continuation function.
continuationOptions
Options for when the continuation is scheduled and how it behaves. This includes criteria, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled" /> , as well as execution options, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously" /> .
public
Task<​TResult>
ContinueWith​(Func<​Task, object, TResult> continuationFunction,
object state,
TaskScheduler scheduler)
Creates a continuation that executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes. The continuation receives caller-supplied state information and uses a specified scheduler.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task`1" /> .
continuationFunction
A function to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.
state
An object representing data to be used by the continuation function.
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> to associate with the continuation task and to use for its execution.
public
Task<​TResult>
ContinueWith​(Func<​Task, TResult> continuationFunction)
Creates a continuation that executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task`1" /> completes and returns a value.
Returns A new continuation task.
continuationFunction
A function to run when the <see cref="T:System.Threading.Tasks.Task`1" /> completes. When run, the delegate will be passed the completed task as an argument.
public
Task<​TResult>
ContinueWith​(Func<​Task, TResult> continuationFunction,
CancellationToken cancellationToken)
Creates a continuation that executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes and returns a value. The continuation receives a cancellation token.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task`1" /> .
continuationFunction
A function to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task as an argument.
cancellationToken
The <see cref="P:System.Threading.Tasks.TaskFactory.CancellationToken" /> that will be assigned to the new continuation task.
public
Task<​TResult>
ContinueWith​(Func<​Task, TResult> continuationFunction,
CancellationToken cancellationToken,
TaskContinuationOptions continuationOptions,
TaskScheduler scheduler)
Creates a continuation that executes according to the specified continuation options and returns a value. The continuation is passed a cancellation token and uses a specified scheduler.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task`1" /> .
continuationFunction
A function to run according to the specified <c>continuationOptions.</c> When run, the delegate will be passed the completed task as an argument.
cancellationToken
The <see cref="P:System.Threading.Tasks.TaskFactory.CancellationToken" /> that will be assigned to the new continuation task.
continuationOptions
Options for when the continuation is scheduled and how it behaves. This includes criteria, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled" /> , as well as execution options, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously" /> .
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> to associate with the continuation task and to use for its execution.
public
Task<​TResult>
ContinueWith​(Func<​Task, TResult> continuationFunction,
TaskContinuationOptions continuationOptions)
Creates a continuation that executes according to the specified continuation options and returns a value.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task`1" /> .
continuationFunction
A function to run according to the condition specified in <paramref name="continuationOptions" /> . When run, the delegate will be passed the completed task as an argument.
continuationOptions
Options for when the continuation is scheduled and how it behaves. This includes criteria, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.OnlyOnCanceled" /> , as well as execution options, such as <see cref="F:System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously" /> .
public
Task<​TResult>
ContinueWith​(Func<​Task, TResult> continuationFunction,
TaskScheduler scheduler)
Creates a continuation that executes asynchronously when the target <see cref="T:System.Threading.Tasks.Task" /> completes and returns a value. The continuation uses a specified scheduler.
Returns A new continuation <see cref="T:System.Threading.Tasks.Task`1" /> .
continuationFunction
A function to run when the <see cref="T:System.Threading.Tasks.Task" /> completes. When run, the delegate will be passed the completed task as an argument.
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> to associate with the continuation task and to use for its execution.
public static
Task
Delay​(int millisecondsDelay)
Creates a task that completes after a specified number of milliseconds.
Returns A task that represents the time delay.
millisecondsDelay
The number of milliseconds to wait before completing the returned task, or -1 to wait indefinitely.
public static
Task
Delay​(int millisecondsDelay,
CancellationToken cancellationToken)
Creates a cancellable task that completes after a specified number of milliseconds.
Returns A task that represents the time delay.
millisecondsDelay
The number of milliseconds to wait before completing the returned task, or -1 to wait indefinitely.
cancellationToken
A cancellation token to observe while waiting for the task to complete.
public static
Task
Delay​(TimeSpan delay)
Creates a task that completes after a specified time interval.
Returns A task that represents the time delay.
delay
The time span to wait before completing the returned task, or <see langword="Timeout.InfiniteTimeSpan" /> to wait indefinitely.
public static
Task
Delay​(TimeSpan delay,
CancellationToken cancellationToken)
Creates a cancellable task that completes after a specified time interval.
Returns A task that represents the time delay.
delay
The time span to wait before completing the returned task, or <see langword="Timeout.InfiniteTimeSpan" /> to wait indefinitely.
cancellationToken
A cancellation token to observe while waiting for the task to complete.
public static
Task
Delay​(TimeSpan delay,
TimeProvider timeProvider)
Creates a task that completes after a specified time interval.
Returns A task that represents the time delay.
delay
The <see cref="T:System.TimeSpan" /> to wait before completing the returned task, or <see cref="F:System.Threading.Timeout.InfiniteTimeSpan" /> to wait indefinitely.
timeProvider
The <see cref="T:System.TimeProvider" /> with which to interpret <paramref name="delay" /> .
public static
Task
Delay​(TimeSpan delay,
TimeProvider timeProvider,
CancellationToken cancellationToken)
Creates a cancellable task that completes after a specified time interval.
Returns A task that represents the time delay.
delay
The <see cref="T:System.TimeSpan" /> to wait before completing the returned task, or <see cref="F:System.Threading.Timeout.InfiniteTimeSpan" /> to wait indefinitely.
timeProvider
The <see cref="T:System.TimeProvider" /> with which to interpret <paramref name="delay" /> .
cancellationToken
A cancellation token to observe while waiting for the task to complete.
public
void
Dispose​()
Releases all resources used by the current instance of the <see cref="T:System.Threading.Tasks.Task" /> class.
protected
void
Dispose​(bool disposing)
Disposes the <see cref="T:System.Threading.Tasks.Task" /> , releasing all of its unmanaged resources.
disposing
A Boolean value that indicates whether this method is being called due to a call to <see cref="M:System.Threading.Tasks.Task.Dispose" /> .
public static
Task
FromCanceled​(CancellationToken cancellationToken)
Creates a <see cref="T:System.Threading.Tasks.Task" /> that's completed due to cancellation with a specified cancellation token.
Returns The canceled task.
cancellationToken
The cancellation token with which to complete the task.
public static
Task<​TResult>
FromCanceled​(CancellationToken cancellationToken)
Creates a <see cref="T:System.Threading.Tasks.Task`1" /> that's completed due to cancellation with a specified cancellation token.
Returns The canceled task.
cancellationToken
The cancellation token with which to complete the task.
public static
Task
FromException​(Exception exception)
Creates a <see cref="T:System.Threading.Tasks.Task" /> that has completed with a specified exception.
Returns The faulted task.
exception
The exception with which to complete the task.
public static
Task<​TResult>
FromException​(Exception exception)
Creates a <see cref="T:System.Threading.Tasks.Task`1" /> that's completed with a specified exception.
Returns The faulted task.
exception
The exception with which to complete the task.
public static
Task<​TResult>
FromResult​(TResult result)
Creates a <see cref="T:System.Threading.Tasks.Task`1" /> that's completed successfully with the specified result.
Returns The successfully completed task.
result
The result to store into the completed task.
GetAwaiter​()
Gets an awaiter used to await this <see cref="T:System.Threading.Tasks.Task" /> .
Returns An awaiter instance.
public static
Task
Run​(Action action)
Queues the specified work to run on the thread pool and returns a <see cref="T:System.Threading.Tasks.Task" /> object that represents that work.
Returns A task that represents the work queued to execute in the ThreadPool.
action
The work to execute asynchronously.
public static
Task
Run​(Action action,
CancellationToken cancellationToken)
Queues the specified work to run on the thread pool and returns a <see cref="T:System.Threading.Tasks.Task" /> object that represents that work. A cancellation token allows the work to be cancelled if it has not yet started.
Returns A task that represents the work queued to execute in the thread pool.
action
The work to execute asynchronously.
cancellationToken
A cancellation token that can be used to cancel the work if it has not yet started. <see cref="M:System.Threading.Tasks.Task.Run(System.Action,System.Threading.CancellationToken)" /> does not pass <paramref name="cancellationToken" /> to <paramref name="action" /> .
public static
Task
Run​(Func<​Task> function)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by <paramref name="function" /> .
Returns A task that represents a proxy for the task returned by <paramref name="function" /> .
function
The work to execute asynchronously.
public static
Task
Run​(Func<​Task> function,
CancellationToken cancellationToken)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by <paramref name="function" /> . A cancellation token allows the work to be cancelled if it has not yet started.
Returns A task that represents a proxy for the task returned by <paramref name="function" /> .
function
The work to execute asynchronously.
cancellationToken
A cancellation token that can be used to cancel the work if it has not yet started. <see cref="M:System.Threading.Tasks.Task.Run(System.Func{System.Threading.Tasks.Task},System.Threading.CancellationToken)" /> does not pass <paramref name="cancellationToken" /> to <paramref name="action" /> .
public
void
RunSynchronously​()
Runs the <see cref="T:System.Threading.Tasks.Task" /> synchronously on the current <see cref="T:System.Threading.Tasks.TaskScheduler" /> .
public
void
RunSynchronously​(TaskScheduler scheduler)
Runs the <see cref="T:System.Threading.Tasks.Task" /> synchronously on the <see cref="T:System.Threading.Tasks.TaskScheduler" /> provided.
scheduler
The scheduler on which to attempt to run this task inline.
public static
Task<​TResult>
Run​(Func<​Task<​TResult>> function)
Queues the specified work to run on the thread pool and returns a proxy for the <see langword="Task(TResult)" /> returned by <paramref name="function" /> . A cancellation token allows the work to be cancelled if it has not yet started.
Returns A <see langword="Task(TResult)" /> that represents a proxy for the <see langword="Task(TResult)" /> returned by <paramref name="function" /> .
function
The work to execute asynchronously.
public static
Task<​TResult>
Run​(Func<​Task<​TResult>> function,
CancellationToken cancellationToken)
Queues the specified work to run on the thread pool and returns a proxy for the <see langword="Task(TResult)" /> returned by <paramref name="function" /> .
Returns A <see langword="Task(TResult)" /> that represents a proxy for the <see langword="Task(TResult)" /> returned by <paramref name="function" /> .
function
The work to execute asynchronously.
cancellationToken
A cancellation token that can be used to cancel the work if it has not yet started. <see cref="M:System.Threading.Tasks.Task.Run``1(System.Func{System.Threading.Tasks.Task{``0}},System.Threading.CancellationToken)" /> does not pass <paramref name="cancellationToken" /> to <paramref name="action" /> .
public static
Task<​TResult>
Run​(Func<​TResult> function)
Queues the specified work to run on the thread pool and returns a <see cref="T:System.Threading.Tasks.Task`1" /> object that represents that work. A cancellation token allows the work to be cancelled if it has not yet started.
Returns A task object that represents the work queued to execute in the thread pool.
function
The work to execute asynchronously.
public static
Task<​TResult>
Run​(Func<​TResult> function,
CancellationToken cancellationToken)
Queues the specified work to run on the thread pool and returns a <see langword="Task(TResult)" /> object that represents that work.
Returns A <see langword="Task(TResult)" /> that represents the work queued to execute in the thread pool.
function
The work to execute asynchronously.
cancellationToken
A cancellation token that can be used to cancel the work if it has not yet started. <see cref="M:System.Threading.Tasks.Task.Run``1(System.Func{``0},System.Threading.CancellationToken)" /> does not pass <paramref name="cancellationToken" /> to <paramref name="action" /> .
public
void
Start​()
Starts the <see cref="T:System.Threading.Tasks.Task" /> , scheduling it for execution to the current <see cref="T:System.Threading.Tasks.TaskScheduler" /> .
public
void
Start​(TaskScheduler scheduler)
Starts the <see cref="T:System.Threading.Tasks.Task" /> , scheduling it for execution to the specified <see cref="T:System.Threading.Tasks.TaskScheduler" /> .
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> with which to associate and execute this task.
public
void
Wait​()
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution.
public
bool
Wait​(int millisecondsTimeout)
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution within a specified number of milliseconds.
Returns <see langword="true" /> if the <see cref="T:System.Threading.Tasks.Task" /> completed execution within the allotted time; otherwise, <see langword="false" /> .
millisecondsTimeout
The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely.
public
bool
Wait​(int millisecondsTimeout,
CancellationToken cancellationToken)
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution. The wait terminates if a timeout interval elapses or a cancellation token is canceled before the task completes.
Returns <see langword="true" /> if the <see cref="T:System.Threading.Tasks.Task" /> completed execution within the allotted time; otherwise, <see langword="false" /> .
millisecondsTimeout
The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely.
cancellationToken
A cancellation token to observe while waiting for the task to complete.
public
void
Wait​(CancellationToken cancellationToken)
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution. The wait terminates if a cancellation token is canceled before the task completes.
cancellationToken
A cancellation token to observe while waiting for the task to complete.
public
bool
Wait​(TimeSpan timeout)
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution within a specified time interval.
Returns <see langword="true" /> if the <see cref="T:System.Threading.Tasks.Task" /> completed execution within the allotted time; otherwise, <see langword="false" /> .
timeout
A <see cref="T:System.TimeSpan" /> that represents the number of milliseconds to wait, or a <see cref="T:System.TimeSpan" /> that represents -1 milliseconds to wait indefinitely.
public
bool
Wait​(TimeSpan timeout,
CancellationToken cancellationToken)
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution.
Returns <see langword="true" /> if the <see cref="T:System.Threading.Tasks.Task" /> completed execution within the allotted time; otherwise, <see langword="false" /> .
timeout
The time to wait, or <see cref="F:System.Threading.Timeout.InfiniteTimeSpan" /> to wait indefinitely
cancellationToken
A <see cref="P:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.
public static
void
WaitAll​(Collections.​Generic.​IEnumerable<​Task> tasks,
CancellationToken cancellationToken = null)
Waits for all of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution unless the wait is cancelled.
tasks
A collection of tasks on which to wait.
cancellationToken
A token to observe while waiting for the tasks to complete.
public static
void
WaitAll​(ReadOnlySpan<​Task> tasks)
Waits for all of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution.
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
public static
void
WaitAll​(Task[] tasks)
Waits for all of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution.
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
public static
bool
WaitAll​(Task[] tasks,
int millisecondsTimeout)
Waits for all of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution within a specified number of milliseconds.
Returns <see langword="true" /> if all of the <see cref="T:System.Threading.Tasks.Task" /> instances completed execution within the allotted time; otherwise, <see langword="false" /> .
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
millisecondsTimeout
The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely.
public static
bool
WaitAll​(Task[] tasks,
int millisecondsTimeout,
CancellationToken cancellationToken)
Waits for all of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution within a specified number of milliseconds or until the wait is cancelled.
Returns <see langword="true" /> if all of the <see cref="T:System.Threading.Tasks.Task" /> instances completed execution within the allotted time; otherwise, <see langword="false" /> .
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
millisecondsTimeout
The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely.
cancellationToken
A <see cref="P:System.Threading.Tasks.TaskFactory.CancellationToken" /> to observe while waiting for the tasks to complete.
public static
void
WaitAll​(Task[] tasks,
CancellationToken cancellationToken)
Waits for all of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution unless the wait is cancelled.
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
cancellationToken
A <see cref="P:System.Threading.Tasks.TaskFactory.CancellationToken" /> to observe while waiting for the tasks to complete.
public static
bool
WaitAll​(Task[] tasks,
TimeSpan timeout)
Waits for all of the provided cancellable <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution within a specified time interval.
Returns <see langword="true" /> if all of the <see cref="T:System.Threading.Tasks.Task" /> instances completed execution within the allotted time; otherwise, <see langword="false" /> .
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
timeout
A <see cref="T:System.TimeSpan" /> that represents the number of milliseconds to wait, or a <see cref="T:System.TimeSpan" /> that represents -1 milliseconds to wait indefinitely.
public static
int
WaitAny​(Task[] tasks)
Waits for any of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution.
Returns The index of the completed <see cref="T:System.Threading.Tasks.Task" /> object in the <paramref name="tasks" /> array.
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
public static
int
WaitAny​(Task[] tasks,
int millisecondsTimeout)
Waits for any of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution within a specified number of milliseconds.
Returns The index of the completed task in the <paramref name="tasks" /> array argument, or -1 if the timeout occurred.
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
millisecondsTimeout
The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely.
public static
int
WaitAny​(Task[] tasks,
int millisecondsTimeout,
CancellationToken cancellationToken)
Waits for any of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution within a specified number of milliseconds or until a cancellation token is cancelled.
Returns The index of the completed task in the <paramref name="tasks" /> array argument, or -1 if the timeout occurred.
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
millisecondsTimeout
The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely.
cancellationToken
A <see cref="P:System.Threading.Tasks.TaskFactory.CancellationToken" /> to observe while waiting for a task to complete.
public static
int
WaitAny​(Task[] tasks,
CancellationToken cancellationToken)
Waits for any of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution unless the wait is cancelled.
Returns The index of the completed task in the <paramref name="tasks" /> array argument.
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
cancellationToken
A <see cref="P:System.Threading.Tasks.TaskFactory.CancellationToken" /> to observe while waiting for a task to complete.
public static
int
WaitAny​(Task[] tasks,
TimeSpan timeout)
Waits for any of the provided <see cref="T:System.Threading.Tasks.Task" /> objects to complete execution within a specified time interval.
Returns The index of the completed task in the <paramref name="tasks" /> array argument, or -1 if the timeout occurred.
tasks
An array of <see cref="T:System.Threading.Tasks.Task" /> instances on which to wait.
timeout
A <see cref="T:System.TimeSpan" /> that represents the number of milliseconds to wait, or a <see cref="T:System.TimeSpan" /> that represents -1 milliseconds to wait indefinitely.
public
Task
WaitAsync​(CancellationToken cancellationToken)
Gets a <see cref="T:System.Threading.Tasks.Task" /> that will complete when this <see cref="T:System.Threading.Tasks.Task" /> completes or when the specified <see cref="P:System.Threading.CancellationToken" /> has cancellation requested.
Returns The <see cref="T:System.Threading.Tasks.Task" /> representing the asynchronous wait. It may or may not be the same instance as the current instance.
cancellationToken
The <see cref="P:System.Threading.CancellationToken" /> to monitor for a cancellation request.
public
Task
WaitAsync​(TimeSpan timeout)
Gets a <see cref="T:System.Threading.Tasks.Task" /> that will complete when this <see cref="T:System.Threading.Tasks.Task" /> completes or when the specified timeout expires.
Returns The <see cref="T:System.Threading.Tasks.Task" /> representing the asynchronous wait. It may or may not be the same instance as the current instance.
timeout
The timeout after which the <see cref="T:System.Threading.Tasks.Task" /> should be faulted with a <see cref="T:System.TimeoutException" /> if it hasn't otherwise completed.
public
Task
WaitAsync​(TimeSpan timeout,
CancellationToken cancellationToken)
Gets a <see cref="T:System.Threading.Tasks.Task" /> that will complete when this <see cref="T:System.Threading.Tasks.Task" /> completes, when the specified timeout expires, or when the specified <see cref="P:System.Threading.CancellationToken" /> has cancellation requested.
Returns The <see cref="T:System.Threading.Tasks.Task" /> representing the asynchronous wait. It may or may not be the same instance as the current instance.
timeout
The timeout after which the <see cref="T:System.Threading.Tasks.Task" /> should be faulted with a <see cref="T:System.TimeoutException" /> if it hasn't otherwise completed.
cancellationToken
The <see cref="P:System.Threading.CancellationToken" /> to monitor for a cancellation request.
public
Task
WaitAsync​(TimeSpan timeout,
TimeProvider timeProvider)
Gets a <see cref="T:System.Threading.Tasks.Task" /> that will complete when this <see cref="T:System.Threading.Tasks.Task" /> completes or when the specified timeout expires.
Returns The <see cref="T:System.Threading.Tasks.Task" /> representing the asynchronous wait. It may or may not be the same instance as the current instance.
timeout
The timeout after which the <see cref="T:System.Threading.Tasks.Task" /> should be faulted with a <see cref="T:System.TimeoutException" /> if it hasn't otherwise completed.
timeProvider
The <see cref="T:System.TimeProvider" /> with which to interpret <paramref name="timeout" /> .
public
Task
WaitAsync​(TimeSpan timeout,
TimeProvider timeProvider,
CancellationToken cancellationToken)
Gets a <see cref="T:System.Threading.Tasks.Task" /> that will complete when this <see cref="T:System.Threading.Tasks.Task" /> completes, when the specified timeout expires, or when the specified <see cref="T:System.Threading.CancellationToken" /> has cancellation requested.
Returns The <see cref="T:System.Threading.Tasks.Task" /> representing the asynchronous wait. It may or may not be the same instance as the current instance.
timeout
The timeout after which the <see cref="T:System.Threading.Tasks.Task" /> should be faulted with a <see cref="T:System.TimeoutException" /> if it hasn't otherwise completed.
timeProvider
The <see cref="T:System.TimeProvider" /> with which to interpret <paramref name="timeout" /> .
cancellationToken
The <see cref="T:System.Threading.CancellationToken" /> to monitor for a cancellation request.
public static
Task
WhenAll​(Collections.​Generic.​IEnumerable<​Task> tasks)
Creates a task that will complete when all of the <see cref="T:System.Threading.Tasks.Task" /> objects in an enumerable collection have completed.
Returns A task that represents the completion of all of the supplied tasks.
tasks
The tasks to wait on for completion.
public static
Task
WhenAll​(ReadOnlySpan<​Task> tasks)
Creates a task that will complete when all of the supplied tasks have completed.
Returns A task that represents the completion of all of the supplied tasks.
tasks
The tasks to wait on for completion.
public static
Task
WhenAll​(Task[] tasks)
Creates a task that will complete when all of the <see cref="T:System.Threading.Tasks.Task" /> objects in an array have completed.
Returns A task that represents the completion of all of the supplied tasks.
tasks
The tasks to wait on for completion.
public static
Task<​TResult[]>
WhenAll​(Collections.​Generic.​IEnumerable<​Task<​TResult>> tasks)
Creates a task that will complete when all of the <see cref="T:System.Threading.Tasks.Task`1" /> objects in an enumerable collection have completed.
Returns A task that represents the completion of all of the supplied tasks.
tasks
The tasks to wait on for completion.
public static
Task<​TResult[]>
WhenAll​(ReadOnlySpan<​Task<​TResult>> tasks)
Creates a task that will complete when all of the supplied tasks have completed.
Returns A task that represents the completion of all of the supplied tasks.
tasks
The tasks to wait on for completion.
public static
Task<​TResult[]>
WhenAll​(Task[] tasks)
Creates a task that will complete when all of the <see cref="T:System.Threading.Tasks.Task`1" /> objects in an array have completed.
Returns A task that represents the completion of all of the supplied tasks.
tasks
The tasks to wait on for completion.
WhenAny​(Collections.​Generic.​IEnumerable<​Task> tasks)
Creates a task that will complete when any of the supplied tasks have completed.
Returns A task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.
tasks
The tasks to wait on for completion.
WhenAny​(Task task1,
Task task2)
Creates a task that will complete when either of the supplied tasks have completed.
Returns A new task that represents the completion of one of the supplied tasks. Its <see langword="Result" /> is the task that completed first.
task1
The first task to wait on for completion.
task2
The second task to wait on for completion.
WhenAny​(ReadOnlySpan<​Task> tasks)
Creates a task that will complete when any of the supplied tasks have completed.
Returns A task that represents the completion of one of the supplied tasks. The return Task's Result is the task that completed.
tasks
The tasks to wait on for completion.
WhenAny​(Task[] tasks)
Creates a task that will complete when any of the supplied tasks have completed.
Returns A task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.
tasks
The tasks to wait on for completion.
WhenAny​(Collections.​Generic.​IEnumerable<​Task<​TResult>> tasks)
Creates a task that will complete when any of the supplied tasks have completed.
Returns A task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.
tasks
The tasks to wait on for completion.
WhenAny​(Task<​TResult> task1,
Task<​TResult> task2)
Creates a task that will complete when either of the supplied tasks have completed.
Returns A task that represents the completion of one of the supplied tasks. The returned task's <typeparamref name="TResult" /> is the task that completed first.
task1
The first task to wait on for completion.
task2
The second task to wait on for completion.
WhenAny​(ReadOnlySpan<​Task<​TResult>> tasks)
Creates a task that will complete when any of the supplied tasks have completed.
Returns A task that represents the completion of one of the supplied tasks. The return Task's Result is the task that completed.
tasks
The tasks to wait on for completion.
WhenAny​(Task[] tasks)
Creates a task that will complete when any of the supplied tasks have completed.
Returns A task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.
tasks
The tasks to wait on for completion.
public static
Collections.​Generic.​IAsyncEnumerable<​Task>
WhenEach​(Collections.​Generic.​IEnumerable<​Task> tasks)
Creates an <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> that will yield the supplied tasks as those tasks complete.
Returns An <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> for iterating through the supplied tasks.
tasks
The tasks to iterate through as they complete.
public static
Collections.​Generic.​IAsyncEnumerable<​Task>
WhenEach​(Task[] tasks)
Creates an <see cref="T:System.Collections.Generic.IAsyncEnumerable`1" /> that will yield the supplied tasks as those tasks complete.
Returns An <see cref="T:System.Collections.Generic.IAsyncEnumerable`1" /> for iterating through the supplied tasks.
tasks
The task to iterate through when completed.
public static
Collections.​Generic.​IAsyncEnumerable<​Task>
WhenEach​(ReadOnlySpan<​Task> tasks)
Creates an <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> that will yield the supplied tasks as those tasks complete.
Returns An <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> for iterating through the supplied tasks.
tasks
The tasks to iterate through as they complete.
public static
Collections.​Generic.​IAsyncEnumerable<​Task<​TResult>>
WhenEach​(Collections.​Generic.​IEnumerable<​Task<​TResult>> tasks)
Creates an <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> that will yield the supplied tasks as those tasks complete.
Returns An <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> for iterating through the supplied tasks.
tasks
The tasks to iterate through as they complete.
public static
Collections.​Generic.​IAsyncEnumerable<​Task<​TResult>>
WhenEach​(Task[] tasks)
Creates an <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> that will yield the supplied tasks as those tasks complete.
Returns An <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> for iterating through the supplied tasks.
tasks
The tasks to iterate through as they complete.
public static
Collections.​Generic.​IAsyncEnumerable<​Task<​TResult>>
WhenEach​(ReadOnlySpan<​Task<​TResult>> tasks)
Creates an <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> that will yield the supplied tasks as those tasks complete.
Returns An <xref data-throw-if-not-resolved="true" uid="System.Collections.Generic.IAsyncEnumerable`1"></xref> for iterating through the supplied tasks.
tasks
The tasks to iterate through as they complete.
Yield​()
Creates an awaitable task that asynchronously yields back to the current context when awaited.
Returns A context that, when awaited, will asynchronously transition back into the current context at the time of the await. If the current <see cref="T:System.Threading.SynchronizationContext" /> is non-null, it is treated as the current context. Otherwise, the task scheduler that is associated with the currently executing task is treated as the current context.
public
bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj
The object to compare with the current object.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public
string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.