TimeProviderTaskExtensions.CreateCancellationTokenSource Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Feedback
https://aka.ms/ContentUserFeedback.
Kommer snart: Under hela 2024 kommer vi att fasa ut GitHub-problem som feedbackmekanism för innehåll och ersätta det med ett nytt feedbacksystem. Mer information finns i:Skicka och visa feedback för