Introduction
Job scheduling in ASP.NET MVC with Quartz.NET is an open source job scheduling framework written in C# for .NET. job scheduling of background tasks that can be used for any application system. Sometimes everyone gets some issue like bulk email sending one by one that takes lot of time. W can use this job scheduling; it works on background tasks in our Application (MVC or ASP.NET websites)
Job scheduling in ASP.NET MVC with Quartz.NET is an open source job scheduling framework written in C# for .NET. job scheduling of background tasks that can be used for any application system. Sometimes everyone gets some issue like bulk email sending one by one that takes lot of time. W can use this job scheduling; it works on background tasks in our Application (MVC or ASP.NET websites)
Figure 1 :
First create a application and install Quartz.NET in our application is via Nuget ,

We can do this by typing Install-Package Quartz at the Package Manager Console prompt or by right clicking on the project in Visual Studio Solution Explorer and select Manage Nuget Packages.
Figure 2 :
Search "quartz" and click Install button,
Three major categories are :
- Defining Job
- Job Trigger
- Job Schedule
Job is the task, Job Trigger is when the job is executed. Job and trigger are combined for execution with the JobScheduler . We have to create a job class which implements the IJob interface defined by quartz.net. This class is called by the quartz.net scheduler at the configured time and should therefore contain your send mail functionality
Defining Job
A job is a class. It implements the Quartz IJob interface and this method defines actions to be performed. The Execute method get IJobExecutionContext object as a parameter. The scheduler passes that in when calling the job's Execute method.
A job is a class. It implements the Quartz IJob interface and this method defines actions to be performed. The Execute method get IJobExecutionContext object as a parameter. The scheduler passes that in when calling the job's Execute method.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using Quartz;
- using System.Net;
- using System.Net.Mail;
- namespace ScheduledTask.Models
- {
- public class Jobclass:IJob
- {
- public void Execute(IJobExecutionContext context)
- {
- using (var message = new MailMessage("[email protected]", "[email protected]"))
- {
- message.Subject = "Message Subject test";
- message.Body = "Message body test at " + DateTime.Now;
- using (SmtpClient client = new SmtpClient
- {
- EnableSsl = true,
- Host = "smtp.gmail.com",
- Port = 587,
- Credentials = new NetworkCredential("[email protected]", "123546")
- })
- {
- client.Send(message);
- }
- }
- }
- }
- }
Job Trigger
Actual code has been placed in a method called Start A scheduler is created and started the job is created using the Quartz.NET JobBuilder.Create<Jobclass> method, where Jobclass is the type of job to be created. Then a trigger is created when a Job should be executed.
We want to run this Job WithIntervalInSeconds once in Seconds . So our trigger definition will look like,
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using Quartz;
- using Quartz.Impl;
- namespace ScheduledTask.Models
- {
- public class JobScheduler
- {
- public static void Start()
- {
- IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
- scheduler.Start();
- IJobDetail job = JobBuilder.Create<Jobclass>().Build();
- ITrigger trigger = TriggerBuilder.Create()
- .WithIdentity("trigger1", "group1")
- .StartNow()
- .WithSimpleSchedule(x => x
- .WithIntervalInSeconds(10)
- .RepeatForever())
- .Build();
- scheduler.ScheduleJob(job, trigger);
- }
- }
- }
JobScheduler in Global asax
The Application_Start event handler in the Global.asax.cs file place for invoke the start method of the JobScheduler.Start, as it would be called the first time the application is started.
The Application_Start event handler in the Global.asax.cs file place for invoke the start method of the JobScheduler.Start, as it would be called the first time the application is started.
Summary:
We learned open source job Scheduling Background Tasks in ASP.NET using Quartz.NET. I hope this article is useful for all .NET beginners.
Read more articles on ASP.NET:

sangamesh hallurPosted Jan 19, 2022, 1:27 PM
Hello, Instated of sending email as background task I am trying to download zip file in background but its not working. Any help/suggestions would be helpful and much appreciated.
Hassan TariqPosted Apr 17, 2021, 11:07 AM
Can anyone tell me how to include anyother service using DI in quartz?
nirmal kumarPosted Jul 15, 2020, 8:44 AM
Can I get your code?
Parshuram KalvikattePosted Dec 19, 2019, 11:15 PM
This is Really a very bad idea of using Quartz in ASP.NET as IIS will stop its Worker Process if there's no request .For IIS to avoid stopping,need to change Pool setting to Always Running ,but it may effect Application Performance.
swatiPosted Jul 19, 2019, 7:35 AM
I have used simple scheduler for a job and it's working fine on local server but on remote server it stops everytime Application_End event is fired. How could i make it work there?
nitesh sahuPosted Dec 9, 2017, 6:56 AM
Nice....I did as instruct, and when I deploy the project to IIS, it does not work. Please help me!!!!
Nguy?n Quân MinhPosted Jan 11, 2017, 11:23 AM
Nice....I did as instruct, and when I deploy the project to IIS, it does not work. Please help me!!!
Sr KarthigaPosted Apr 22, 2016, 7:57 AM
good one
Amin JariwalaPosted Apr 22, 2016, 2:57 AM
Can I run 10k jobs in single application? Suppose I have auction facility in my application and when auction will expire then automatically email will throw to owner that your auction has been expired. So how can I create dynamic Jobs auction wise because there are multiple auctions and multiple sellers.
Rajeesh MenothPosted Apr 12, 2016, 10:46 AM
Good Buddy!!
Raja TPosted Apr 12, 2016, 6:38 AM
Nice,Thanks for sharing ..
Jaipal ReddyPosted Apr 12, 2016, 4:47 AM
Good one. .
Mohammed IbrahimPosted Apr 11, 2016, 1:45 PM
nice
Kuppurasu NagarajPosted Apr 11, 2016, 1:14 PM
Nice Sharing
NitinPosted Apr 11, 2016, 12:16 PM
Nice