tags:

views:

824

answers:

3

I'm developing a C# program that needs to be able to schedule a variety of asynchronous tasks at different times. I need a solution that activates every second to check for tasks to execute, and eats up as few resources as possible. It also needs to scale well to a large number of tasks. Which of these is better to use, or is there any ?

1) Using a System.Timers.Timer object with a 1 second elapsed time to trigger an event that executes tasks, or

2) Using a separate thread that sleeps for 1 second and then executes tasks when it wakes up, or

3) Something else entirely.

+1  A: 

Try looking at Quartz.Net for your scheduling needs. I think it's pretty good.

ZombieSheep
+2  A: 

http://weblogs.asp.net/jgalloway/archive/2005/10/24/428303.aspx

John Sheehan
This is a great suggestion, although the OP did mention a large number of tasks. I inferred that they also repeat although it was not stated.
ZombieSheep
Task Scheduler handles repeating tasks and has a lot more scheduling/repeating options than you could easily build.
John Sheehan
A: 

System.Threading.Timer is extremely lightweight. You could create a separate timer for each task so that the timer comes due when the task is supposed to execute.

Internally, I believe that the system will keep track of what timer is due next so it only has to monitor one timer at any given time (source/similar question).

Michael Haren
added reference to a similar question
Michael Haren