EP 3 : Schedule 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 the following packages from the Nuget Package Manager

Microsoft.Data.SqlClient

Microsoft.Extensions.Hosting

Quartz

Quartz.Extensions.Hosting

Quartz.Serialization.Json

Step 2: Create Job

Step 3: Configure Program.cs

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

await builder.Services.ConfigureQuartzScheduler();

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

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

  • Where I have used WithSimpleSchedule you can use Calendar/CRON as per your needs

There are 3 ways you can help me in growing:

  1. Subscribe to my YouTube Channel

  2. Subscribe to my Weekly .NET Newsletter of C#/.NET

  3. Download my eBook at Gum Road which contains 30+ .NET Tips