views:

162

answers:

4

A design question:
I'd like to build a Windows service that executes different commands at different intervals. For simplicity's sake, let's say I want to run some batch files.

The input it gets is a list of files and the intervals at which to execute.
For example:
a.bat - 4 minutes
b.bat - 1 minute
c.bat - 1 minute
d.bat - 2 minutes

I was thinking about sorting them according to intervals, and then setting a timer for each of the intervals. I'm not sure this is the best solution and I'd be happy to hear some feedbacks.
Thanks!

+2  A: 

You can use Quartz.NET library to schedule different tasks.

Giorgi
+1  A: 

I have a Windows service that does something similar (generating reports at specified times). I solved this using Quartz.NET.

Ronald Wildenberg
A: 

Not all problems are nails that should be solved with the C# hammer. Use the Microsoft Scheduled Tasks.

Oliver
Thanks, but I really need a hammer in this case. The scenario I described is simplified, and the actual one can't be based on the scheduled tasks.
Nir
@Nir: Ok, if you already know this windows feature and it doesn't match, it is ok to do this yourself and Quartz.Net is the way to go.
Oliver
A: 

Well since you're using C#, why not create threads instead of using timers? Then set the thread for a batch file to sleep or run at different intervals.

techiesguy
Because I need the tasks to run at intervals. I don't know how this can be done with threads without using some kind of a timer.
Nir