目录

Public Constructor Summary

Constructor name
TaskCompletionSource()
TaskCompletionSource(CancellationToken token)
Creates an instance of TaskCompletionSource with a CancellationToken so that the task can be canceled when CancellationToken is canceled.

Public Method Summary

Return typeMethod name
voidsetResult(TResult result)
Returns the task instance.
booleantrySetResult(TResult result)
Completes the task with the specified result, unless the task has already been completed. If the task has already been completed, nothing will be done.
booleantrySetException(Exception exception)
Completes the task with the specified result, unless the task has already been completed. If the task has already been completed, nothing will be done.
Task< TResult >getTask()
Returns the task instance.

Public Constructors

constructor
public TaskCompletionSource()
constructor
public TaskCompletionSource(CancellationToken token)
Creates an instance of TaskCompletionSource with a CancellationToken so that the task can be canceled when CancellationToken is canceled.

Parameters

Parameter nameParameter desc
tokenTransfers the notification that operations should be canceled.

Public Methods

Method
public void setResult(TResult result)
Returns the task instance.

Parameters

Parameter nameParameter desc
resultTransfers the notification that operations should be canceled.
Method
public void trySetResult(TResult result)
Completes the task with the specified result, unless the task has already been completed. If the task has already been completed, nothing will be done.

Parameters

Parameter nameParameter desc
resultResult of the task.

Return
typedesc
booleantrue if the result is set successfully, false otherwise.
Method
public boolean trySetException(Exception exception)
Completes the task with the specified exception, unless the task has already been completed. If the task has already been completed, nothing will be done.

Parameters

Parameter nameParameter desc
exceptionException object.

Return
typedesc
booleantrue if the exception is set successfully, false otherwise.
Method
public Task< TResult > getTask()
Returns the task instance.

Return

typedesc
Task< TResult >Task instance.