Job Scheduling in ASP.NET MVC Website using Quartz Scheduler

By: Amit Bhagwani
Updated: June 13th, 2019 | Technology: Asp.Net, Asp.Net MVC, E-Commerce
Job Scheduling in ASP.NET MVC Website using Quartz Scheduler

In this article, I will show you how to schedule a job in ASP.NET MVC using quartz scheduler library.

Introduction:

Every ASP.NET MVC Developers know that how to create ASP.NET MVC web applications that run in the background but most of the time such background tasks are handled by creating windows service with timer or console based application. we are going to discuss one job scheduling in ASP.NET MVC program by using quartz DLL libraries.

Now you have an ASP.NET MVC web-based application where you want to perform job scheduling(run some tasks in the background) by quartz job scheduler as the scheduled interval.

Now, we can call any asp.net method using AJAX on the timely based interval basis. but what happens if there is no traffic on your asp.net website. here we have one solution for job scheduling through we can create a background job scheduling which keeps on running even if there are not any live website visitor.

So that finally, we have to create a web form which can run continuously in the background in ASP.NET MVC web application which constantly runs in the background using ASP.NET MVC web form?

Problems with Job Scheduling in ASP.NET MVC Website:

ASP.NET web form doesn’t provide such controls or methods which able to call method once per defined time interval like call method after every 2 hours later, call a method after every 1 day later or call a method after every 1 month later, etc.

So here I am going to show you how to run a background job in ASP.NET as well I will show you what are the configuration settings which needs to be done to keep web application running even after 20 minutes of default ideal time.

Solutions:

There is a DLL ( dynamic link library) which provide this kind of functionality. It is called quartz.net scheduler.

This is simple to understand and easy to implement, Please download the DLL or NuGet package for the  quartz.net and everything is there for a project to get started.

Note: You can install this package on NuGet package console by typing following command.

Install-Package Quartz:

Here is the job scheduler solution in ASP.NET C# sample code is as follow.

Create Class for job schedule which inherits the IJob class of quartz.net.

Example:

Then create another executable method where you can job schedule for your bunch of tasks.

Example:

This trigger will run every minute.

Note: There is more way to create trigger you can check the site for more details.

Then call the schedule in application start.

Example:

This will start a job schedule for the event which runs in the background every minute.

Now there is one additional setting in IIS, this will keep your IIS application pool to keep alive until your web server is restarted.

  1. Open the web server IIS
  2. Go to the ApplicationPool
  3. Choose your App pool
  4. Open Recycling
  5. Set Regular Time Interval to 0 (Zero)

These settings will not recycle your App pool even if it is not visible to the world for a long period of time.

I hope this all information will work for you.

Contact Us