3

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 !

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Leo Le
  • 815
  • 3
  • 13
  • 33

1 Answers1

6

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.

Tallmaris
  • 7,605
  • 3
  • 28
  • 58
  • I stumbled to the same solution. However, is there a nice GUI (i.e. like Outlook's GUI Appointment Repeat) dialog for asp.net MVC? – Colin Oct 01 '13 at 04:15
  • A GUI for doing what? Generally speaking you don't want a service to have a GUI, or you will need to enable desktop integration. If you need some confit, either create a mmc addin or a simple app that modifies data in a db, the registry or an XML file where then the service can read from. – Tallmaris Oct 03 '13 at 18:12
  • Hi Tallmaris, thanks for the comment. I'm using the scheduler to execute jobs that are created by the business. Some jobs need to be scheduled for certain time periods, hence a UI. – Colin Oct 10 '13 at 15:48
  • 1
    Understood. In this case, then, rather than giving a UI to a Windows Service application, I would suggest to create anotehr app, which could be a web or a desktop application, or even a MMC plugin. These can have a UI as you like. In turn, the app will store the wanted schedule values somewhere where the windows service can pick them up (be that hte registry or db or an xml file). – Tallmaris Oct 11 '13 at 09:19
  • Good idea. Currently I have an ASP.net/MVC app where jobs are created, and one of the options of the job is to defer or schedule the execution. I have Quartz.net running as a standalone Windows service on the App server, with the SQL Server as the job persistence backing store. Unfortunately I completely underestimated the effort for the scheduling UI on the web front end. C'est la vie. – Colin Oct 15 '13 at 18:15