Skip to content

v1.0.0-preview.2

Pre-release
Pre-release
Compare
Choose a tag to compare
@egil egil released this 20 May 09:17
· 60 commits to main since this release

This 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 a CancellationTokenSource via the method TimeProvider.CreateCancellationTokenSource(TimeSpan delay) or in .NET 8, using new 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 the CancellationTokenSource object returned by CreateCancellationTokenSource(TimeSpan delay). This action will not terminate the initial timer indicated by the delay argument initially passed the CreateCancellationTokenSource method. However, this restriction does not apply on .NET 8.0 and later versions.
  • To enable controlling PeriodicTimer via TimeProvider in versions of .NET earlier than .NET 8.0, the TimeProvider.CreatePeriodicTimer returns a PeriodicTimerWrapper object instead of a PeriodicTimer object. The PeriodicTimerWrapper type is just a lightweight wrapper around the original System.Threading.PeriodicTimer and will behave identically to it.