Need help writing a simple scheduler

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.
 
C

Cezary Nolewajka

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top