TimeProviderTaskExtensions.Delay Method

Definition

Creates a task that completes after a specified time interval.

C#
public static System.Threading.Tasks.Task Delay(this TimeProvider timeProvider, TimeSpan delay, System.Threading.CancellationToken cancellationToken = default);

Parameters

timeProvider
TimeProvider

The TimeProvider with which to interpret delay.

delay
TimeSpan

The TimeSpan to wait before completing the returned task, or InfiniteTimeSpan to wait indefinitely.

cancellationToken
CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

A task that represents the time delay.

Exceptions

The timeProvider argument is null.

delay represents a negative time interval other than InfiniteTimeSpan.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)