问题
I've built a website application by ASP.NET MVC that helps user get RSS news. Of course, it works perfectly. However, I want to expand the function that the website will automatic send hot news to user's email at 6.00 am daily, for example.
I've found solutions on internet but I still confused among using Quartz.NET, Windows Service, and Schedule in windows.
Please tell me where I should begin !
Thanks so much !
回答1:
First of all you will need to create a windows service: http://msdn.microsoft.com/en-us/library/zt39148a.aspx
Quartz.NET has a useful tutorial here: http://quartznet.sourceforge.net/tutorial/lesson_1.html
What I would do would be to initialize your scheduler in the OnStart()
override and eventually stop it in the OnStop()
.
Basically you can define triggers using the Trigger
class and Jobs by creating an implementation of the IJob
interface, then use the scheduler to attach triggers to jobs. Everytime a trigger fires, the Execute
method of the Job is run.
Putting the entire explanation here would be way too long, but following the tutorials should get you where you want to be in matter of minutes. Good luck!
Of the other end, there is a much simpler solution than writing a windows service. Just write a console app and then, through the Task Scheduler interface (Control Panel -> Administrative Tools in Win 7), create a task that runs your app at the time you want. For a simple task that needs to run once a day this is probably a better solution rather than keeping a service up 24/7.
来源:https://stackoverflow.com/questions/17296183/scheduler-for-web-application-asp-net-mvc