Need help writing a simple scheduler

  • Thread starter Thread starter Oleg Ogurok
  • Start date Start date
O

Oleg Ogurok

Hi all,

I'm trying to write a simple Windows Service that will "do something" at a
given time, for example call a method at 5pm.
What's the easiest way to schedule a task like that in C# ? All I can think
of right now is checking the system clock every minute or so until it hits
5pm, but I feel there has to be a better way.

Note, please don't offer Windows Scheduler. I'm trying to learn here ;)

Thanks in advance,

-Oleg.
 
1) You can use the Timer class.

When the system starts, check how much time is left until 5pm and set the
timer to fire an event after the calculated interval.

Then, every time the event is fired, configure appropriately the Timer using
the above attitued when you finish processing

2) Your proposal is all right as well, but remember, that you need to start
a new thread in the OnStart method of the system service to perform looping
and checking the time.
 
Back
Top