Reputation: 1940
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.
Upvotes: 0
Views: 573
Reputation: 66882
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.
Upvotes: 1
Reputation: 18096
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.
Upvotes: 1
Reputation: 5251
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
Upvotes: 0