Cron Jobs / Scheduled Tasks for your Website

Michael Strong
2 min readDec 6, 2018

Quartz.NET is a library used to make something happen at a set interval. The best example would be Quartz can be used to email someone every 15 mins for an update. Let's say an important package is to arrive and we need to track it. Your customer is super needy and wants plenty of emails to keep them informed. Quartz can do this, it will send that email automatically. Another library that will do this is Hangfire, its more popular however more complex to setup.

To setup Quartz on you website you need to add the NuGet Package and enable the Global.asax file. This file can be added just like you add any other page, right click the Project and Add Item.

Once the Global.asax file is added just call a method under Application_Start. This method creates an object and needs a few items to function.

We create the JobScheduler and add a recurring job plus a trigger. The actual job just needs to inherit the class IJob. Where IJob is what was pre-written to make this class work. In the above example the class EmailJob is just something that the job does, in my case it sends an email. The trigger can be whatever you like, every 15 mins, every 1st tuesday, ect. I suggest Googling commonly used triggers as they do seem a bit tricky.

And that's it really. Once you host this app the first time the app loads the process starts. However, there is a slight draw back, as of recently certain web hosts will close your app when there are no users surfing. In my experience it does not happen often.

--

--

Michael Strong

Living in south west Ontario Canada. Father of two. Working full time as a software engineer at a major transportation software company.