firing an event at specific time or interval

  • Thread starter Thread starter Aussie Rules
  • Start date Start date
A

Aussie Rules

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
 
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.
 
Funny how long it took Microsoft to decide that this was the way to do
it. They had multiple timers instead of one timer that serviced a time
sorted queue.

We all had to be careful not to use too many timers. There were 16 and
that was it! Try to use a 17th one and your program was history. And
you have no idea how many were in use. What a stupid idea!!

"The IRQ is in use." -- Really, WHAT IRQ???

"The file cannot be found." -- If you would just tell me the filename, I
COULD HELP!

"An unexpected error has occurred." -- ALL errors are unexpected. HELP
ME with some indication of what the error is! Oh, I see, you won't.
Thanks?

There are stronger answers to these STILL EXISTING error messages but
they are not fit to type here.

Mike
 
Back
Top