Class ReactiveTimer
Represents a disposable timer that can be listened to.
public sealed class ReactiveTimer : ConcurrentEventSource<WithInterval<long>, EventPublisher<WithInterval<long>>>, IEventSource<WithInterval<long>>, IEventStream<WithInterval<long>>, IEventSource, IEventStream, IDisposable
- Inheritance
-
ReactiveTimer
- Implements
- Inherited Members
- Extension Methods
Constructors
ReactiveTimer(ITimestampProvider, Duration, Duration, long)
Creates a new ReactiveTimer instance.
public ReactiveTimer(ITimestampProvider timestampProvider, Duration interval, Duration spinWaitDurationHint, long count = 9223372036854775807)
Parameters
timestampProviderITimestampProviderTimestamp provider used for time tracking.
intervalDurationInterval between subsequent timer events.
spinWaitDurationHintDurationSpinWait duration hint for this timer.
countlongNumber of events this timer will emit in total. Equal to MaxValue by default.
Exceptions
- ArgumentOutOfRangeException
When
countis less than 1 or whenintervalis less than 1 tick or greater than MaxValue milliseconds or whenspinWaitDurationHintis less than 0.
ReactiveTimer(ITimestampProvider, Duration, long)
Creates a new ReactiveTimer instance.
public ReactiveTimer(ITimestampProvider timestampProvider, Duration interval, long count = 9223372036854775807)
Parameters
timestampProviderITimestampProviderTimestamp provider used for time tracking.
intervalDurationInterval between subsequent timer events.
countlongNumber of events this timer will emit in total. Equal to MaxValue by default.
Exceptions
- ArgumentOutOfRangeException
When
countis less than 1 or whenintervalis less than 1 tick or greater than MaxValue milliseconds.
Fields
DefaultSpinWaitDurationHint
Specifies the default SpinWait duration hint. Equal to 1 microsecond.
public static readonly Duration DefaultSpinWaitDurationHint
Field Value
Properties
Count
Number of events this timer will emit in total.
public long Count { get; }
Property Value
Interval
Interval between subsequent timer events.
public Duration Interval { get; }
Property Value
State
Specifies the current state of this timer.
public ReactiveTimerState State { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public override void Dispose()
Run()
Attempts to run this timer.
public void Run()
Exceptions
- ObjectDisposedException
The timer has been disposed.
- InvalidOperationException
The timer is not in Idle state.
Run(Duration)
Attempts to run this timer with an initial delay.
public void Run(Duration delay)
Parameters
delayDurationTime that must elapse before emitting the first event.
Exceptions
- ObjectDisposedException
The timer has been disposed.
- InvalidOperationException
The timer is not in Idle state.
- ArgumentOutOfRangeException
When
delayis less than 1 tick or greater than MaxValue milliseconds.
Stop()
Attempts to stop this timer.
public bool Stop()
Returns
- bool
true when timer was marked for stopping, otherwise false.