How to Implement Background Task Scheduling in ASP.NET Core 10 Using Quartz.NET and C# (2026)

A warehouse audit must begin at 8 a.m. on weekdays, even when the ASP.NET Core process restarts during a deployment. Quartz.NET models that requirement as a job with a calendar trigger. Store the schedule in SQL Server when it needs to survive a restart. Then decide explicitly whether a missed firing should run late, and protect the business operation from duplicate effects.

What is Quartz.NET scheduling?

A job identifies work and a trigger identifies when it is eligible to run. The scheduler acquires eligible triggers, activates a job through dependency injection, and records trigger state in its job store. Multiple triggers can refer to one job key. This is useful when a manual run and a recurring schedule must share the same concurrency rule.

Quartz acquires a scheduled trigger and executes its job through ASP.NET Core dependency injection.
Quartz acquires a scheduled trigger and executes its job through ASP.NET Core dependency injection.
Decision This tutorial Why it matters
Trigger Weekdays at 08:00 in a named time zone Business calendars belong in a named zone
Misfire Skip missed cron firings Avoid replaying a stale daily audit automatically
Storage Memory locally, SQL Server for durability Process memory disappears on restart
Overlap Disallow concurrent execution per job key Two triggers for the same job should not overlap

Quartz cron syntax begins with a seconds field. The expression 0 0 8 ? * MON-FRI specifies zero seconds, zero minutes, and eight in the morning on weekdays. The question mark leaves the day-of-month field unspecified. Verify schedules in your actual zone, especially if a local time can fall in a daylight-saving gap or occur twice. Add an explicit holiday calendar when weekdays and business days differ.

Build the ASP.NET Core 10 scheduler

Install the .NET 10 SDK. Create a web project with a single Program.cs. Keep all Quartz packages on the same 3.x release. The companion project records the versions resolved during the build.

BASH
dotnet new web -n InventoryCalendar -f net10.0
cd InventoryCalendar
dotnet add package Quartz.Extensions.Hosting --version '3.*'
dotnet add package Quartz.Serialization.SystemTextJson --version '3.*'
dotnet add package Microsoft.Data.SqlClient --version '6.1.*'
Program.cs
using Quartz;

var builder = WebApplication.CreateBuilder(args);
var connection = builder.Configuration.GetConnectionString("Quartz");
var cluster = builder.Configuration.GetValue<bool>("Scheduler:Cluster");
var zoneId = builder.Configuration["Scheduler:TimeZone"] ?? "UTC";
var zone = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
if (cluster && string.IsNullOrWhiteSpace(connection))
    throw new InvalidOperationException("Clustering requires shared SQL Server storage.");

builder.Services.AddQuartz(q =>
{
    q.SchedulerName = "InventoryCalendar";
    if (!string.IsNullOrWhiteSpace(connection))
    {
        q.SchedulerId = "AUTO";
        q.UsePersistentStore(store =>
        {
            store.UseProperties = true;
            store.UseSqlServer(connection);
            store.UseSystemTextJsonSerializer();
            if (cluster) store.UseClustering();
        });
    }
    var key = new JobKey("inventory-audit", "warehouse");
    q.AddJob<InventoryAudit>(j => j.WithIdentity(key));
    q.AddTrigger(t => t.WithIdentity("weekday-audit", "warehouse")
        .ForJob(key).WithCronSchedule("0 0 8 ? * MON-FRI", c =>
            c.InTimeZone(zone).WithMisfireHandlingInstructionDoNothing()));
    if (string.IsNullOrWhiteSpace(connection) && builder.Environment.IsDevelopment())
        q.AddTrigger(t => t.WithIdentity("development-smoke", "warehouse")
            .ForJob(key).StartNow());
});
builder.Services.AddQuartzHostedService(o => o.WaitForJobsToComplete = true);

var app = builder.Build();
app.MapGet("/", () => new { schedule = "08:00 weekdays", zone = zone.Id });
app.Run();

[DisallowConcurrentExecution]
public sealed class InventoryAudit(ILogger<InventoryAudit> log) : IJob
{
    public async Task Execute(IJobExecutionContext context)
    {
        var ct = context.CancellationToken;
        log.LogInformation("Audit started for {Job} at scheduled time {FireTime}",
            context.JobDetail.Key, context.ScheduledFireTimeUtc);
        // Replace with idempotent work keyed by the intended business period.
        await Task.Delay(TimeSpan.FromMilliseconds(200), ct);
        log.LogInformation("Audit completed for {Job}", context.JobDetail.Key);
    }
}

The no-connection Development path adds an immediate trigger to demonstrate host startup. Production can omit that trigger while keeping the same job definition. Job details and trigger identities are stable across deployments. Review what should happen if a deployment changes cron or deletes a trigger. Persistent storage retains prior definitions and the registration behavior must match your deployment policy.

Enable durable SQL Server scheduling

Create a disposable scheduler database and apply Quartz’s SQL Server schema from the same release as the library. The schema is Quartz infrastructure. Apply it as a reviewed deployment step with a schema identity. Give the runtime identity only the rights needed to read and update the scheduler tables. Set the connection string through ConnectionStrings__Quartz or a local secret, and set Scheduler__TimeZone to a zone supported by the host. Use UTC in the first test so all replicas agree.

Enable Scheduler__Cluster=true on every intended member before running multiple instances against the same tables. Keep scheduler name, database, schema and settings compatible, and give each member a distinct scheduler instance ID. Keep clocks synchronized and allow enough time to complete jobs during shutdown. A job configured for recovery can run again after a failure, so cluster coordination still needs application idempotency.

Verify a firing, a misfire, and a restart

Start the Development memory lab and check that the smoke trigger logs one execution. Read the root endpoint to confirm the configured schedule and time zone. For the SQL test, remove the development trigger by setting the connection and temporarily change the cron expression to a short staging interval. Start the host, observe a firing, stop it across several scheduled intervals, then restart. The intended cron policy skips old firings once Quartz classifies them as misfires. An interval shorter than the configured misfire threshold may not exercise that path.

BASH
ASPNETCORE_ENVIRONMENT=Development dotnet run --no-launch-profile --urls http://localhost:5077
curl -fsS http://localhost:5077/

For a cluster exercise, start two replicas with the same durable scheduler configuration. Track each job key, scheduler instance, planned firing and actual start. Add a deliberately slow job in the staging fixture to check overlap rules. A job key identifies the concurrency boundary. The same job class registered under another key can still run in parallel.

How should jobs retry and stop?

Pass the Quartz cancellation token to I/O and make shutdown cooperative. For a transient downstream failure, prefer a bounded delay and a retry plan with a deadline. An immediate refire can saturate an unhealthy dependency if each attempt fails quickly. For a billing or inventory operation, record its business period or operation ID in a durable table with a unique constraint. Decide whether the business outcome should be inserted or replayed in one transaction.

Measure trigger lag, job duration, failure count and missed occurrences. Alert on a schedule that did not produce the expected result, rather than merely on a running scheduler process. Keep the job’s own workload out of the scheduler database transaction. Readiness should distinguish a temporarily unavailable dependency from a scheduler process that must be restarted.

Does Quartz replace a queue?

Quartz schedules work by time. A queue buffers requests and distributes them to workers. A scheduled job can publish a durable command and let a queue manage delivery.

Why did my weekday job fire at a different hour?

Compare the configured time zone and daylight-saving rules on each host. Inspect the previous and next trigger fire times in UTC, then translate them to the business zone.

References

Comments