I'm new to the whole concept of ASP.NET, so please be patient with me. My requirement is to create a scheduling component that will do some tasks that are stored in a database. What's the most common way of implementing this. My idea is to store intervals as TimeSpan and somehow poll my database in very short intervals.
-
You need a more clear and detailed question. – Caimen Feb 23 '12 at 19:36
-
ASP.Net does not seem like a good fit for this requirement. You would be better off using a windows service for this. – John Koerner Feb 23 '12 at 19:51
3 Answers
I would like to recommend to implement task executor as Windows Service.
Here are some approaches:
The service may periodically polls the database and perform the tasks.
Using MSMQ. It allows to use system-wide queues: one process (ASP.NET web application) can produce queue items, another one (the service) - consume them. How to do asynchronous programming using ASP.NET, MSMQ and Windows Service, for long running processes.

- 17,291
- 7
- 48
- 81
For more advanced scheduling scenarios, Quartz.net is a very useful tool - http://quartznet.sourceforge.net/ - ported from Java (I think).
As others are pointing out, ASP.Net's lifecycle isn't well suited to regular scheduled tasks. However, I've seen several web apps and web app frameworks (e.g. DotNetNuke and YetAnotherForum, I think) which perform scheduled tasks by occasionally borrowing threadpool threads after web hits have been serviced. This is very useful in shared hosting models where you're normally restricted in what you can install on the server.

- 66,722
- 7
- 114
- 165
If you're looking at short intervals, you usually use a Timer class - there are several in the Framework e.g. System.Timers.Timer and System.Threading.Timer. You set the Interval as a number of milliseconds (using the TimeSpan static methods such as FromSeconds or FromMinutes for ease of reading)
Look at System.Timers.Timer vs System.Threading.Timer for a comparison of the two timers