Skip to content

ScheduledTask<TResult>.WaitAsync(TimeSpan, CancellationToken)

WaitAsync(TimeSpan, CancellationToken)

View source
public Task<TResult> WaitAsync(TimeSpan timeout, CancellationToken cancellationToken = default(CancellationToken))
Waits for and returns the successful result, and requests durable cancellation of the task once timeout elapses.

Parameters

timeoutTimeSpan
The time to wait before requesting cancellation, which is zero or positive.
cancellationTokenCancellationToken
A token which abandons the wait. It doesn't cancel the task.

Returns

The task's result, including a result which it returns after observing the timeout's cancellation request.

Exceptions

System.ArgumentOutOfRangeException
timeout is negative, including System.Threading.Timeout.InfiniteTimeSpan; await the task to wait without a timeout. Outside a durable execution, timeout also exceeds the longest timer interval which System.Threading.CancellationTokenSource.CancelAfter accepts.
System.TimeoutException
The timeout elapsed, and the task ended canceled.