Trigger event at specified time

  • Thread starter Thread starter qm
  • Start date Start date
Q

qm

I'm thinking I must be missing something...

I have a service running on my server. I want this
service to fire off an event at 1:57pm (13:57).

How can I do this? In reality, the timing of the event(s)
will be listed on a SQL table, so it isn't like there will
be just one event, there is potential for several dozen
events (and perhaps several event handlers) that will need
to be fired off throughout the day.

Thanks for your help
qm.
 
Why don't you just read all those events from the table and create a timer
to check if it is time to fire off any of them every X seconds ?
If you don't have a specifc event type for each event, you can raise a more
generic event and pass the event type or name in the event arguments.

Something like this:

private Timer tmr = new Timer(new TimerCallBack(Timer_Elapsed), null, 0,
10000);


private void Timer_Elapsed(object state)
{
foreach(YourEventType ev in someEventTypeCollection)
{
//check if that event is due and raise an event
}
}
 
Check out Waitable Timers in the Win32 documentation, and use
WaitForMultipleObjects() to signal your worker thread to do whatever. That
method should work for what it sounds like you want.
 
Back
Top