v1.0.0-preview.2
Pre-releaseThis release adds a dependency on Microsoft.Bcl.TimeProvider and utilizes the types built-in to that to do much of the work.
Compared to the previous version (TimeScheduler) of this library, this release includes the following changes:
-
Removed
CancelAfter
extension methods. Instead, create aCancellationTokenSource
via the methodTimeProvider.CreateCancellationTokenSource(TimeSpan delay)
or in .NET 8, usingnew CancellationTokenSource(TimeSpan delay, TimeProvider timeProvider)
.NOTE: If running on .NET versions earlier than .NET 8.0, there is a constraint when invoking CancellationTokenSource.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.
Known issues and limitations:
- When using the
ManualTimeProvider
during testing to forward time, be aware of this issue: dotnet/runtime#85326. - If running on .NET versions earlier than .NET 8.0, there is a constraint when invoking
CancellationTokenSource.CancelAfter(TimeSpan)
on theCancellationTokenSource
object returned byCreateCancellationTokenSource(TimeSpan delay)
. This action will not terminate the initial timer indicated by thedelay
argument initially passed theCreateCancellationTokenSource
method. However, this restriction does not apply on .NET 8.0 and later versions. - To enable controlling
PeriodicTimer
viaTimeProvider
in versions of .NET earlier than .NET 8.0, theTimeProvider.CreatePeriodicTimer
returns aPeriodicTimerWrapper
object instead of aPeriodicTimer
object. ThePeriodicTimerWrapper
type is just a lightweight wrapper around the originalSystem.Threading.PeriodicTimer
and will behave identically to it.