Releases: egil/TimeProviderExtensions
v1.0.0
v1.0.0-rc.3
Strong named the assembly. By @quinmars.
v1.0.0-rc.2
-
Added
ActiveTimersproperty toManualTimeProvider. The property will display the number of currently active timers that have a callback scheduled to be called in the future. -
Allow
ManualTimeProvider.Startto be set using property initializers. -
Made the timer type created by
ManualTimeProvider, theManualTimertype, public, and introduced a protected methodCreateManualTimeronManualTimeProvider. This enables advanced scenarios where a customManualTimeris needed.A custom implementation of
ManualTimercan override theChangemethod and add custom behavior to it.Overriding
CreateManualTimermakes it possible to intercept aTimerCallbackand perform actions before and after the timer callback has been invoked. -
Replace the
AutoAdvanceAmountproperty with theAutoAdvanceBehaviorproperty onManualTimeProvider, and introduce theAutoAdvanceBehaviortype. To automatically advance the time whenGetUtcNow()orGetLocalNow()is called, setAutoAdvanceBehavior.UtcNowAdvanceAmountto aTimeSpanlarger than zero. -
Enable auto advance feature for
GetTimestamp()andGetElapsedTime(long). To automatically advance the time whenGetTimestamp()orGetElapsedTime(long)is called, setAutoAdvanceBehavior.TimestampAdvanceAmountto aTimeSpanlarger than zero. -
ManualTimernow exposes its current configuration.DueTime,Period,IsActive,CallbackTime, andCallbackInvokeCountare now publicly visible. -
Enable auto-advance feature for timers. This enables automatically calling timers callback a specified number of times, by setting the
AutoAdvanceBehavior.TimerAutoTriggerCountproperty to a number larger than zero.
Full Changelog: v1.0.0-rc.1...v1.0.0-rc.2
v1.0.0-rc.1
- Updated Microsoft.Bcl.TimeProvider package dependency to rc.1 version.
v1.0.0-preview.7
- Added support for netstandard2.0, as this is supported by the back-port package https://www.nuget.org/packages/Microsoft.Bcl.TimeProvider.
v1.0.0-preview.6
- Added
Jump(TimeSpan)andJump(DateTimeOffset)methods that will jump time to the specified place. Any timer callbacks between the start and end of the jump will be invoked the expected number of times, but the date/time returned fromGetUtcNow()andGetTimestamp()will always be the jump time. This differs from howAdvanceandSetUtcNowworks. See the readme for a detailed description.
v1.0.0-preview.5
Aligned the public API surface of ManualTimeProvider with Microsoft.Extensions.Time.Testing.FakeTimeProvider. This means:
- The
StartTimeproperty is now calledStart. - The
ForwardTimemethod has been removed (useAdvanceinstead). - The
AutoAdvanceAmountproperty has been introduced, which will advance time with the specified amount every timeGetUtcNow()is called. It defaults toTimeSpan.Zero, which disables auto-advancing.
v1.0.0-preview.4
- Added 'StartTime' to
ManualTestProvider, which represents the initial date/time when theManualtTimeProviderwas initialized.
v1.0.0-preview.3
- Changed
ManualTestProvidersets the local time zone to UTC by default, provides method for overriding during testing. - Changed
ManualTestProvider.ToString()method to return current date time. - Fixed
ITimerreturned byManualTestProvidersuch that timers created with a due time equal to zero will fire the timer callback immediately.
v1.0.0-preview.2
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
CancelAfterextension methods. Instead, create aCancellationTokenSourcevia 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
ManualTimeProviderduring 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 theCancellationTokenSourceobject returned byCreateCancellationTokenSource(TimeSpan delay). This action will not terminate the initial timer indicated by thedelayargument initially passed theCreateCancellationTokenSourcemethod. However, this restriction does not apply on .NET 8.0 and later versions. - To enable controlling
PeriodicTimerviaTimeProviderin versions of .NET earlier than .NET 8.0, theTimeProvider.CreatePeriodicTimerreturns aPeriodicTimerWrapperobject instead of aPeriodicTimerobject. ThePeriodicTimerWrappertype is just a lightweight wrapper around the originalSystem.Threading.PeriodicTimerand will behave identically to it.