Task Scheduler in C# (.NET): Quartz.NET, Hangfire and Coravel

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Task Scheduler in C# (.NET): Quartz.NET, Hangfire and Coravel



In modern .NET applications, it is often necessary to execute code not only upon user request, but also on a schedule: sending email newsletters, database cleanup, report generation, synchronization with external APIs. For this purpose, Job Schedulers are used. In this article, we will look at three popular tools for C# (.NET): Quartz.NET, Hangfire and Coravel, their features, code examples, and usage scenarios.



Why do you need a task scheduler in .NET?

A task scheduler allows you to:

  • Execute background jobs at a specific time (e.g., every day at 8:00 AM).
  • Repeat tasks at a specified interval (every 5 minutes).
  • Process job queues without blocking the main application thread.
  • Easily manage tasks (add, delete, pause).
  • Ensure fault tolerance (retry attempts on errors).


1. Quartz.NET — Powerful and Flexible Scheduler

Quartz.NET is a port of the popular Java framework Quartz for .NET. It supports complex schedules (cron expressions), clustering, and job persistence in a database. Suitable for enterprise projects.



Installation

dotnet add package Quartzdotnet add package Quartz.Extensions.Hosting


Example: Job with cron schedule

using Quartz;using Quartz.Impl;using System.Threading.Tasks;

public class EmailJob : IJob{ public async Task Execute(IJobExecutionContext context) { Console.WriteLine($"Sending email at {DateTime.Now}"); // Email sending logic await Task.CompletedTask; }}

// Configuration in Program.csvar scheduler = await StdSchedulerFactory.GetDefaultScheduler();await scheduler.Start();

var job = JobBuilder.Create<EmailJob>() .WithIdentity("emailJob", "group1") .Build();

var trigger = TriggerBuilder.Create() .WithIdentity("emailTrigger", "group1") .WithCronSchedule("0 0 8 * * ?") // Every day at 8:00 AM .Build();

await scheduler.ScheduleJob(job, trigger);


Features

  • Support for cron expressions (flexible scheduling).
  • Clustering for distributed systems.
  • Persistence (jobs are saved on restart).
  • High performance for thousands of jobs.


2. Hangfire — Simplicity and Built-in UI

Hangfire is a scheduler with minimal configuration and a built-in web dashboard for job monitoring. Great for small and medium projects where quick integration is important.



Installation

dotnet add package Hangfiredotnet add package Hangfire.SqlServer (for database storage)


Example: Simple job with delay and recurrence

using Hangfire;using Hangfire.SqlServer;

// Configuration in Program.csGlobalConfiguration.Configuration .UseSqlServerStorage("YourConnectionString");

app.UseHangfireServer();app.UseHangfireDashboard(); // Access at /hangfire

// Creating a jobBackgroundJob.Schedule(() => Console.WriteLine("Delayed job"), TimeSpan.FromMinutes(5));RecurringJob.AddOrUpdate("daily-report", () => Console.WriteLine("Daily report"), Cron.Daily);


Features

  • Built-in web interface for monitoring (no additional dependencies).
  • Support for queues, retries, and delayed jobs.
  • Easy integration with ASP.NET Core.
  • Job storage in SQL Server, Redis, PostgreSQL.


3. Coravel — Lightweight and Modern

Coravel is a minimalist scheduler for .NET, inspired by Laravel. Requires no external dependencies

Recommendations