The first thing you need to do is determine how little tolerance you can
live with for your 'forward' time-based events. For example, will it be
absolutely critical that they are fired at the exact time or will it be
alright if they are fired at a point up to 'some small time span' after the
nomintaed time (say, 1 minute)?
If it is the former then you are going to have jump through some hoops.
If it is the latter then it is relatively simple by implementing something
like:
Set the interval for your timer to the desired value,
(say 60000 - 1 minute)
Instantiate a queue object (preferably a generic one).
Enqueue a DateTime object for each required 'trigger point'.
Each 'trigger point' will represent it's next occurrence,
(e.g., 2 AM on Friday 23 May 2008).
When the Tick event for the timer fires, Peek the first
object in the queue.
If DateTime.Now >= 'the object' then DeQueue the object
and 'fire' the appropriate event.
In your 'event' EnQueue a new DateTime object for the next
occurrence of the required 'trigger point',
(e.g., 2 AM on Friday 30 May 2008).
When the application is termintaed, the content of the queue could be
persisted to a file and when the application is instantiated, the queue
could be repopulated from the file, so the whole mechanism can survive
restarts etc.
"Aussie Rules" <au****@nospam.comwrote in message
news:Ow*************@TK2MSFTNGP05.phx.gbl...
Hi,
I want to be able to to have an event fired within my application at a
certain time on certain days (such as 2am Monday, Wednesday and Friday) as
well as other timers that fire an event based on a time interval (such as
every 3 minutes).
Out of the box there is the old timer1, which would cover the second
scenario, but is there a way to have the first timer done?
There maybe upto 50 different timers within the application.
Thanks