Schedule Background Jobs with Quartz.NET

What is Quartz.NET

There are many ways to schedule background jobs, but two are particularly well-known. Quartz and Hangfire. I talked about Hangfire in a recent LinkedIn post. Today we are going to learn about Quartz.

Quartz.NET is used for scheduling jobs with some additional features over Hangfire. CRON triggers, calendar events, and simple events are all supported.

How to use it ?

  1. Install Packages
  2. Create Job
  3. Configure Program.cs

Step 1 : Install Packages

Install following packages from Nuget Package Manager

  • Microsoft.Data.SqlClient
  • Microsoft.Extensions.Hosting
  • Quartz
  • Quartz.Extensions.Hosting
  • Quartz.Serialization.Json

Step 2 : Create Job

Scheduling Background Jobs with Quartz in .NET

Step 3 : Configure Program.cs

I have created an extension method for IServiceCollections and called it in Program.cs like this :

Scheduling Background Jobs with Quartz in .NET

await builder.Services.ConfigureQuartzScheduler();

Let’s see how our scheduler code looks like :

Scheduling Background Jobs with Quartz in .NET

Key points :

  1. If we want to use our own storage then we can configure SQL otherwise it will automatically use our RAM Job Store.

  2. Using With Identity to group jobs while creating the jobs and triggering them.

  3. Where I have used WithSimpleSchedule you can use Calendar/CRON as per your need’s

After running the application that’s how our console looks like :

Scheduling Background Jobs with Quartz in .NET

This article was originally published at https://mwaseemzakir.substack.com/ on .

Whenever you're ready, there are 3 ways I can help you:

  1. Subscribe to my youtube channel : For in-depth tutorials, coding tips, and industry insights.
  2. Promote yourself to 9,000+ subscribers : By sponsoring this newsletter
  3. Patreon community : Get access to all of my blogs and articles at one place