Breyta

Deila með


TimeProviderTaskExtensions.CreateCancellationTokenSource Method

Definition

Initializes a new instance of the CancellationTokenSource class that will be canceled after the specified TimeSpan.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Threading::CancellationTokenSource ^ CreateCancellationTokenSource(TimeProvider ^ timeProvider, TimeSpan delay);
public static System.Threading.CancellationTokenSource CreateCancellationTokenSource (this TimeProvider timeProvider, TimeSpan delay);
static member CreateCancellationTokenSource : TimeProvider * TimeSpan -> System.Threading.CancellationTokenSource
<Extension()>
Public Function CreateCancellationTokenSource (timeProvider As TimeProvider, delay As TimeSpan) As CancellationTokenSource

Parameters

timeProvider
TimeProvider

The TimeProvider with which to interpret the delay.

delay
TimeSpan

The time interval to wait before canceling this CancellationTokenSource.

Returns

CancellationTokenSource that will be canceled after the specified delay.

Exceptions

The delay is negative and not equal to InfiniteTimeSpan or greater than maximum allowed timer duration.

Remarks

The countdown for the delay starts during the call to the constructor. When the delay expires, the constructed CancellationTokenSource is canceled if it has not been canceled already.

If running on .NET versions earlier than .NET 8.0, there is a constraint when invoking CancelAfter(TimeSpan) on the resultant object. This action will not terminate the initial timer indicated by delay. However, this restriction does not apply on .NET 8.0 and later versions.

Applies to