TaskCompletionSource.TrySetFromTask(Task) Method

Definition

Attempts to transition the underlying Task<TResult> into the same completion state as the specified completedTask.

C#
public bool TrySetFromTask(System.Threading.Tasks.Task completedTask);

Parameters

completedTask
Task

The completed task whose completion status (including exception or cancellation information) should be copied to the underlying task.

Returns

true if the operation was successful; otherwise, false.

Exceptions

completedTask is null.

completedTask is not completed.

Remarks

This operation will return false if the Task<TResult> is already in one of the three final states: RanToCompletion, Faulted, or Canceled.

Applies to

Product Versions
.NET 9, 10