# Quartz.NET — Enterprise Job Scheduler for .NET > A full-featured, open-source job scheduling library for .NET that supports cron expressions, persistent job stores, and clustering for reliable background task execution. ## Install Save as a script file and run: # Quartz.NET — Enterprise Job Scheduler for .NET ## Quick Use ```bash dotnet add package Quartz dotnet add package Quartz.Extensions.Hosting ``` ```csharp builder.Services.AddQuartz(q => { q.UseMicrosoftDependencyInjectionJobFactory(); q.ScheduleJob(trigger => trigger .WithCronSchedule("0 0/5 * * * ?")); }); builder.Services.AddQuartzHostedService(); ``` ## Introduction Quartz.NET is a .NET port of the popular Java Quartz scheduler. It provides enterprise-grade job scheduling with support for cron triggers, calendar exclusions, persistent job stores, and clustered execution across multiple application instances. ## What Quartz.NET Does - Schedules jobs using cron expressions, simple intervals, or calendar-based triggers - Persists job and trigger state to SQL databases for durability across restarts - Supports clustered scheduling where multiple nodes share a job store without duplicate execution - Manages job dependencies, retry policies, and misfire handling strategies - Integrates with ASP.NET Core dependency injection and hosted services ## Architecture Overview Quartz.NET has three core abstractions: Jobs (the work to execute), Triggers (when to execute), and the Scheduler (the orchestrator). The scheduler runs as a hosted service and checks triggers against the current time. In clustered mode, an ADO.NET job store with row-level locking ensures only one node fires each trigger. An in-memory store is available for simpler single-instance scenarios. ## Self-Hosting & Configuration - Install via NuGet: `dotnet add package Quartz` and `Quartz.Extensions.Hosting` - Register with `AddQuartz()` and `AddQuartzHostedService()` in `Program.cs` - Use `UsePersistentStore()` with SQL Server, PostgreSQL, or SQLite for durable scheduling - Enable clustering with `q.UsePersistentStore(s => s.UseProperties = true)` and shared DB - Configure misfire policies per trigger to handle delayed or missed firings ## Key Features - Cron expression support identical to Unix cron with seconds-level precision - Persistent job stores survive application restarts and deployments - Cluster-safe scheduling prevents duplicate job execution across instances - Calendar exclusions for holidays, maintenance windows, and business hours - Listener interfaces for monitoring job execution, triggers, and scheduling events ## Comparison with Similar Tools - **Hangfire** — Focuses on background jobs with a dashboard; Quartz.NET excels at complex scheduling with cron and calendars - **Celery** — Python distributed task queue; Quartz.NET serves the same role in .NET - **Azure Functions Timer** — Cloud-only; Quartz.NET runs on-premises or in any hosting environment - **Coravel** — Simpler .NET scheduler; Quartz.NET offers clustering and persistent stores for enterprise needs ## FAQ **Q: Does Quartz.NET support dependency injection?** A: Yes, the `Quartz.Extensions.Hosting` package integrates fully with Microsoft DI. **Q: Can jobs run across multiple servers?** A: Yes, enable clustered mode with a shared database and Quartz.NET coordinates execution. **Q: What happens if a job fails?** A: You can configure retry policies, and jobs can request re-execution by throwing a `JobExecutionException`. **Q: How precise is the scheduling?** A: Triggers support second-level precision with cron expressions like `0/30 * * * * ?` for every 30 seconds. ## Sources - https://github.com/quartznet/quartznet - https://www.quartz-scheduler.net/documentation --- Source: https://tokrepo.com/en/workflows/asset-0dee5dcb Author: Script Depot