views:

475

answers:

4

Hello everybody.

I'm working on a program that will need to delete a folder (and then re-instantiate it) at a certain hour of the day, and this hour will be given by the user.

The hour will most likely be during the night, because that's when nobody is accessing the folder (it's outside working hours). Is there a way to trigger that event at that certain hour?

I know about timers, but is there an easier way to do this without a timer that ticks and checks to see what time it is?

EDIT: Maybe I wasn't specific enough. I want to trigger a method to do something, without having to first compile it in a separate executable. This method is part of a bigger class that is implemented as a Windows Service. So this service continuously runs, but at a certain time of day, it should trigger this function to delete the folder.

Thanks.

+5  A: 

Think out of the box.

No need for coding on this kind of job - use Scheduled Tasks, they have been in windows for a long time. You can kick off your program from this.

Update: (following update to question)

If you need to trigger a method from an already running service, use a timer and test DateTime.Now against your target time.

Oded
Thanks, good idea. Also found this link that could prove helpful for others:http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/8240ca9c-a70e-4827-b5ff-c576d632862c
Andrei
A: 

A possible start or guideline : NCrontab

markcial
+3  A: 

Use Windows Scheduler. There you can specificy which file is executed when.

citronas
+1  A: 

The programmatic interface for Scheduled Task is COM-based, so it should be relatively easy to use it from .NET (though I've never tried myself).

Dean Harding