Click or drag to resize

RecurringTimer Class

Used to manage tasks that need to be performed on a periodic basis.
Inheritance Hierarchy
SystemObject
  Neon.TimeRecurringTimer

Namespace:  Neon.Time
Assembly:  Neon.Common (in Neon.Common.dll) Version: 2.2.0
Syntax
public class RecurringTimer

The RecurringTimer type exposes the following members.

Constructors
  NameDescription
Public methodRecurringTimer
Default constructor that creates a Disabled timer.
Public methodRecurringTimer(String)
Constructs a timer by parsing a string value.
Public methodRecurringTimer(TimeOfDay)
Constructs a recurring timer that will fire once a day at the specified time offset.
Public methodRecurringTimer(RecurringTimerType, TimeSpan)
Constructs a recurring timer of the specified type and time offset from the beginning of the implied period.
Top
Properties
  NameDescription
Public propertyStatic memberDisabled
Returns a disabled timer.
Public propertyTimeOffset
Returns the TimeSpan offet from the beginning of the period when the timer is scheduled to fire.
Public propertyType
Returns the timer type.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodHasFired
Determines whether the timer has fired by comparing the current UTC time with the scheduled event time.
Public methodHasFired(DateTime)
Determines if the timer has fired by comparing the current time passed with the next scheduled firing time.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodReset
Resets the timer to fire at the next scheduled interval after the current UTC time.
Public methodReset(DateTime)
Resets the timer to fire at the next scheduled interval after the time passed.
Public methodSet
Sets the firing time for the timer.
Public methodStart
Starts the timer by computing the next firing time after the current time (UTC).
Public methodStart(DateTime)
Starts the timer by computing the next firing time after the time passed.
Public methodToString
Renders the timer into a string.
(Overrides ObjectToString.)
Public methodStatic memberTryParse
Attempts to parse RecurringTimer from a string.
Public methodWaitAsync
Waits aynchronously for the timer to fire.
Top
Remarks

This timer is designed to be polled periodically from an application's background thread by calling the HasFired or HasFired(DateTime) methods. These methods will return true if the action associated with the timer is to be performed.

This class works by watching for the transition between a call to HasFired made at a time before the scheduled event and then a subsequent call made when the current time is at or after the scheduled event time. HasFired will return true on the subsequent call if the time is right.

This behavior ensures that scheduled tasks will only be executed once for any recurring schedule, even if the application is restarted.

The HasFired method uses the current UTC time to perform the time comparison. The HasFired(DateTime) will use the time passed (which may be local time, etc.) to do this.

Note Note

This timer auto resets after HasFired returns true. Note also that HasFired must be called fairly frequently (on the order of a few minutes or less) to obtain reasonable accuracy.

Asynchronous applications may find it more convienent to call WaitAsync(TimeSpan) to wait for the timer to fire.

The Reset and Reset(DateTime) methods may be used to explictly reset the timer to fire at the next scheduled time. This may be useful for ensuring that short duration timers are properly reset after an operation that may take longer to complete than the timer interval.

Recurring timers are represented as strings with the format of the string depending on the type of timer. The table below describes these formats:

Disabled

Disabled timers never fire. Simply place the word Disabled at the beginning of the timer string.

Minute

Minute timers fire at the top of every minute. There is no offset. Minute timers are formatted as:

Examples
Minute
QuarterHour

Quarter hour timers are fired four times an hour at the offset from the 15 minute time. Quarter hour timers formatted as:

Examples
QuarterHour QuarterHour:MM QuarterHour:MM:SS
Hourly

Hourly timers are fired once per hour at the offset from the top of the hour. Hourly timers are formatted as:

Examples
Hourly Hourly:MM Hourly:MM:SS
Daily

Daily timers are fired once per day at the specified time of day. Daily timers are formatted as:

Examples
Daily Daily:HH:MM Daily:HH:MM:SS
Interval

Interval timers are fired on a regular interval that is not not tied to a specific period. Interval timers are formatted as:

Examples
Interval:HH:MM:SS
Thread Safety
Instance members of this type are not safe for multi-threaded operations.
See Also