CancellationTokenSource.CancelAfter Method

Definition

Schedules a cancel operation on this CancellationTokenSource.

Overloads

CancelAfter(Int32)

Schedules a cancel operation on this CancellationTokenSource after the specified number of milliseconds.

CancelAfter(TimeSpan)

Schedules a cancel operation on this CancellationTokenSource after the specified time span.

CancelAfter(Int32)

Source:
CancellationTokenSource.cs
Source:
CancellationTokenSource.cs
Source:
CancellationTokenSource.cs

Schedules a cancel operation on this CancellationTokenSource after the specified number of milliseconds.

C#
public void CancelAfter(int millisecondsDelay);

Parameters

millisecondsDelay
Int32

The time span to wait before canceling this CancellationTokenSource.

Exceptions

The exception thrown when this CancellationTokenSource has been disposed.

The exception thrown when millisecondsDelay is less than -1.

Remarks

The countdown for the millisecondsDelay starts during this call. When the millisecondsDelay expires, this CancellationTokenSource is canceled, if it has not been canceled already.

Subsequent calls to CancelAfter will reset the millisecondsDelay for this CancellationTokenSource, if it has not been canceled already.

Applies to

.NET 10 ja muut versiot
Tuote Versiot
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

CancelAfter(TimeSpan)

Source:
CancellationTokenSource.cs
Source:
CancellationTokenSource.cs
Source:
CancellationTokenSource.cs

Schedules a cancel operation on this CancellationTokenSource after the specified time span.

C#
public void CancelAfter(TimeSpan delay);

Parameters

delay
TimeSpan

The time span to wait before canceling this CancellationTokenSource.

Exceptions

The exception thrown when this CancellationTokenSource has been disposed.

delay.TotalMilliseconds is less than -1 or greater than Int32.MaxValue (or UInt32.MaxValue - 1 on some versions of .NET). Note that this upper bound is more restrictive than TimeSpan.MaxValue.

Remarks

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

Subsequent calls to CancelAfter will reset the delay for this CancellationTokenSource, if it has not been canceled already.

Applies to

.NET 10 ja muut versiot
Tuote Versiot
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0