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
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
TaskCreationOptions
CreationOptions
Gets the <see cref="T:System.Threading.Tasks.TaskCreationOptions" /> used to create this 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
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)
continueOnCapturedContext
<see langword="true" /> to attempt to marshal the continuation back to the original context captured; otherwise, <see langword="false" /> .
Returns An object used to await this task.
Configures an awaiter used to await this <see cref="T:System.Threading.Tasks.Task" /> .
ConfigureAwait​(ConfigureAwaitOptions options)
options
Options used to configure how awaits on this task are performed.
Returns An object used to await this task.
Configures an awaiter used to await this <see cref="T:System.Threading.Tasks.Task" /> .
public
Task
ContinueWith​(Action`2 continuationAction,
object state,
CancellationToken cancellationToken)
public
Task
ContinueWith​(Action`2 continuationAction,
object state,
CancellationToken cancellationToken,
TaskContinuationOptions continuationOptions,
TaskScheduler scheduler)
public
Task
ContinueWith​(Action`2 continuationAction,
object state,
TaskContinuationOptions continuationOptions)
public
Task
ContinueWith​(Action`2 continuationAction,
object state,
TaskScheduler scheduler)
public
Task
ContinueWith​(Action`1 continuationAction,
CancellationToken cancellationToken)
public
Task
ContinueWith​(Action`1 continuationAction,
CancellationToken cancellationToken,
TaskContinuationOptions continuationOptions,
TaskScheduler scheduler)
public
Task
ContinueWith​(Action`1 continuationAction,
TaskContinuationOptions continuationOptions)
public
Task`1
ContinueWith​(Func`3 continuationFunction,
object state,
CancellationToken cancellationToken)
public
Task`1
ContinueWith​(Func`3 continuationFunction,
object state,
CancellationToken cancellationToken,
TaskContinuationOptions continuationOptions,
TaskScheduler scheduler)
public
Task`1
ContinueWith​(Func`3 continuationFunction,
object state,
TaskContinuationOptions continuationOptions)
public
Task`1
ContinueWith​(Func`3 continuationFunction,
object state,
TaskScheduler scheduler)
public
Task`1
ContinueWith​(Func`2 continuationFunction,
CancellationToken cancellationToken)
public
Task`1
ContinueWith​(Func`2 continuationFunction,
CancellationToken cancellationToken,
TaskContinuationOptions continuationOptions,
TaskScheduler scheduler)
public
Task`1
ContinueWith​(Func`2 continuationFunction,
TaskContinuationOptions continuationOptions)
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)
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" /> .
Disposes the <see cref="T:System.Threading.Tasks.Task" /> , releasing all of its unmanaged resources.
GetAwaiter​()
Returns An awaiter instance.
Gets an awaiter used to await this <see cref="T:System.Threading.Tasks.Task" /> .
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)
scheduler
The scheduler on which to attempt to run this task inline.
Runs the <see cref="T:System.Threading.Tasks.Task" /> synchronously on the <see cref="T:System.Threading.Tasks.TaskScheduler" /> provided.
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)
scheduler
The <see cref="T:System.Threading.Tasks.TaskScheduler" /> with which to associate and execute this task.
Starts the <see cref="T:System.Threading.Tasks.Task" /> , scheduling it for execution to the specified <see cref="T:System.Threading.Tasks.TaskScheduler" /> .
public
void
Wait​()
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution.
public
bool
Wait​(int millisecondsTimeout)
millisecondsTimeout
The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite" /> (-1) to wait indefinitely.
Returns <see langword="true" /> if the <see cref="T:System.Threading.Tasks.Task" /> completed execution within the allotted time; otherwise, <see langword="false" /> .
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution within a specified number of milliseconds.
public
bool
Wait​(int millisecondsTimeout,
CancellationToken cancellationToken)
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.
Returns <see langword="true" /> if the <see cref="T:System.Threading.Tasks.Task" /> completed execution within the allotted time; otherwise, <see langword="false" /> .
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.
public
void
Wait​(CancellationToken cancellationToken)
cancellationToken
A cancellation token to observe while waiting for the task to complete.
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.
public
bool
Wait​(TimeSpan timeout)
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.
Returns <see langword="true" /> if the <see cref="T:System.Threading.Tasks.Task" /> completed execution within the allotted time; otherwise, <see langword="false" /> .
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution within a specified time interval.
public
bool
Wait​(TimeSpan timeout,
CancellationToken cancellationToken)
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.
Returns <see langword="true" /> if the <see cref="T:System.Threading.Tasks.Task" /> completed execution within the allotted time; otherwise, <see langword="false" /> .
Waits for the <see cref="T:System.Threading.Tasks.Task" /> to complete execution.
public
Task
WaitAsync​(CancellationToken cancellationToken)
cancellationToken
The <see cref="P:System.Threading.CancellationToken" /> to monitor for a cancellation request.
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.
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.
public
Task
WaitAsync​(TimeSpan timeout)
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.
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.
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.
public
Task
WaitAsync​(TimeSpan timeout,
CancellationToken cancellationToken)
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.
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.
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.
public
Task
WaitAsync​(TimeSpan timeout,
TimeProvider timeProvider)
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" /> .
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.
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.
public
Task
WaitAsync​(TimeSpan timeout,
TimeProvider timeProvider,
CancellationToken cancellationToken)
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.
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.
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.
public
bool
Equals​(object obj)
Inherited from object
obj
The object to compare with the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
Determines whether the specified object is equal to 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
Returns A hash code for the current object.
Serves as the default hash function.
public
Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates 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.