Fire event at predetermined time

nbrege

Freshman
Joined
Jan 12, 2006
Messages
34
I need to make an application that performs a task at a given time each day, based on the system time. For a simple example, lets say I want to delete all the files in a folder at 11:00 am everyday. The program would obviously be running on a computer thats always on. What is the best way to do this? Do I continuously compare the current time with the target time & when they're equal fire the event? This seems like a waste of cpu resources, but maybe thats the only way to do it. Can somebody post some code to get me started on this? Thanks...
 
Whilst you could program this, you could program something to achieve the effect and set it up using the windows task scheduler (thus not needing the timer code). Just a suggestion.
 
Rather than writing a service that is always running, why not write just a little program that does the job you need it to do and just that job (in this case deleting files) and use the Windows' Scheduled Tasks to allow it to run when you want it to run?

Heck, if all you're doing is deleting files rather then writing a program at all, write a batch file. That will do the trick and that's pretty darn easy.
 
Well, Cags, it appears that great minds do think alike! We must have been writing at the exact same time. :D
 
If task scheduler just can't handle your needs, there are better things to do than constantly compare time. The thread should probably spend most of it's time sleeping, hopping on once every minute or so, checking the time, and going back to sleep. This can be done with a Timer class or the Thread.Sleep() method.
 
Back
Top