asp.net mvc2 task scheduler
I have an asp.net mvc 2 app, and I need to run a task (call WS, save into db) once a day. What is the su开发者_C百科ggested way for this? One thing, I have a feeling I would like to execute this task from within the webapp.
Does anyone have any suggestions: I was considering .net quartz or regular System.Timers.Timer? Does anyone see any problems?
Any other better solutions?
Thanks a lot --MB
Why do you want to run this from the webapp? You have no way of even knowing if the webapp will be running at the required time. I would recommend you look at Windows Services
web apps are not the best host for a scheduled task. Unless you implement a system to keep the process awake, there's no chance to be sure your schedule will be executed. Quartz.net is good for that. It consists in a core module which you can use in your web app to save tasks and a server (windows service) module which executes your scheduled jobs.
I've recently implemented my own windows services and used Sql Server as storage for my scheduled jobs. Everything works pretty well, even if, I had to struggle a little bit to put things together. The documentations is not always so clear.
Have a look at Quartz.Net, which is available as a NuGet package or from their site.
There are lots of examples of how to set these up, they are very flexible, you just have to define a class which implements IJob
with a single Execute()
method which gets fired by your choice of triggers.
You could also consider using Windows Workflow Foundation.
精彩评论