asp.net mvc2 task scheduler

醉酒当歌 提交于 2019-12-12 06:09:28

问题


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 suggested 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


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6111910/asp-net-mvc2-task-scheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!