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.​TaskCompletionSource
Assembly: System.Runtime
Inheritance: object → TaskCompletionSource
Represents the producer side of a <see cref="T:System.Threading.Tasks.Task" /> unbound to a delegate, providing access to the consumer side through the <see cref="T:System.Threading.Tasks.Task" /> property.
Properties
public
Task
Task
Gets the <see cref="T:System.Threading.Tasks.Task" /> created by this <see cref="T:System.Threading.Tasks.TaskCompletionSource" /> .
Methods
public
void
SetCanceled​()
Transitions the underlying <see cref="T:System.Threading.Tasks.Task" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Canceled" /> state.
public
void
SetCanceled​(CancellationToken cancellationToken)
cancellationToken
The cancellation token with which to cancel the <see cref="T:System.Threading.Tasks.Task" /> .
Transitions the underlying <see cref="T:System.Threading.Tasks.Task" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Canceled" /> state using the specified token.
public
void
SetException​(Exception exception)
exception
The exception to bind to this <see cref="T:System.Threading.Tasks.Task" /> .
Transitions the underlying <see cref="T:System.Threading.Tasks.Task" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Faulted" /> state.
public
void
SetFromTask​(Task completedTask)
completedTask
The completed task whose completion status (including exception or cancellation information) should be copied to the underlying task.
Transitions the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the same completion state as the specified <paramref name="completedTask" /> .
public
void
SetResult​()
Transitions the underlying <see cref="T:System.Threading.Tasks.Task" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.RanToCompletion" /> state.
public
bool
TrySetCanceled​() Returns <see langword="true" /> if the operation was successful; otherwise, <see langword="false" /> .
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Canceled" /> state.
public
bool
TrySetCanceled​(CancellationToken cancellationToken)
cancellationToken
The cancellation token with which to cancel the <see cref="T:System.Threading.Tasks.Task" /> .
Returns <see langword="true" /> if the operation was successful; otherwise, <see langword="false" /> .
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Canceled" /> state.
public
bool
TrySetException​(Exception exception)
exception
The exception to bind to this <see cref="T:System.Threading.Tasks.Task" /> .
Returns <see langword="true" /> if the operation was successful; otherwise, <see langword="false" /> .
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Faulted" /> state.
public
bool
TrySetFromTask​(Task completedTask)
completedTask
The completed task whose completion status (including exception or cancellation information) should be copied to the underlying task.
Returns <see langword="true" /> if the operation was successful; otherwise, <see langword="false" /> .
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the same completion state as the specified <paramref name="completedTask" /> .
public
bool
TrySetResult​() Returns <see langword="true" /> if the operation was successful; otherwise, <see langword="false" /> .
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.RanToCompletion" /> state.
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.