Class LazyTimer
- Namespace
- Garyon.Mechanisms
- Assembly
- Garyon.dll
Represents a timer that lazily evaluates whether the signal has been raised and the denoted timeout has elapsed, without raising events in real time, and only operating on demand.
public class LazyTimer
- Inheritance
-
LazyTimer
- Inherited Members
- Extension Methods
Constructors
LazyTimer(DateTime)
public LazyTimer(DateTime nextSignal)
Parameters
nextSignalDateTimeThe value to set to the NextSignal property.
Properties
NextSignal
Determines when the next signal is considered raised.
public DateTime NextSignal { get; set; }
Property Value
Remarks
It is possible to overwrite the next signal timestamp when it has timed out, without having evaluated the timeout. In other words, there is no guarantee that this property's value is the same since the last reset, and it does not rely on a timeout to allow the value change.
SignalRaised
Determines whether the timer has timed out, given the current value of the NextSignal property, compared against Now.
public bool SignalRaised { get; }
Property Value
Methods
Initialize(TimeSpan)
Initializes a new LazyTimer with a given TimeSpan representing the offset from the current time, initializing the NextSignal time using Reset(TimeSpan).
public static LazyTimer Initialize(TimeSpan nextSignalSpan)
Parameters
nextSignalSpanTimeSpanThe TimeSpan offsetting the current time that will be set as the timestamp for the next signal.
Returns
- LazyTimer
A new LazyTimer instance with the NextSignal initialized to the current time offset by the given time span.
InitializeRaised()
Initializes a new LazyTimer such that it is initially marked as though the signal has been raised.
public static LazyTimer InitializeRaised()
Returns
- LazyTimer
A new LazyTimer instance with the NextSignal initialized to the current time representing a timer whose signal has been raised.
Remarks
The timer's next signal can be manually adjusted at any moment; this factory method does not prevent mutating the state of the timer.
InitializeUnraised()
Initializes a new LazyTimer such that it is initially marked as though the signal has not yet been raised.
public static LazyTimer InitializeUnraised()
Returns
- LazyTimer
A new LazyTimer instance with the NextSignal initialized to MaxValue.
Remarks
The timer's next signal can be manually adjusted at any moment; this factory method does not prevent mutating the state of the timer.
Reset(TimeSpan)
Resets the timer and adjusts the next signal timestamp based on the current time and the timespan offsetting the current time.
public void Reset(TimeSpan nextSignalSpan)
Parameters
nextSignalSpanTimeSpanThe TimeSpan offsetting the current time that will be set as the timestamp for the next signal.
ResetIfRaisedSignal(TimeSpan)
Resets the timer only if the signal has been raised, and adjusts the next signal timestamp based on the current time and the timespan offsetting the current time.
public bool ResetIfRaisedSignal(TimeSpan nextSignalSpan)
Parameters
nextSignalSpanTimeSpanThe TimeSpan offsetting the current time that will be set as the timestamp for the next signal if the timer is reset.
Returns
- bool
true if the signal had been raised and its next signal timestamp was adjusted, otherwise false.
ResetUnraisable()
Resets the timer and sets the next signal timestamp to MaxValue, effectively making the signal unraisable for until the next signal timestamp is reset to a more approachable date.
public void ResetUnraisable()