TL;DR: In .NET (pronounced dot net) apps, use a hosted service for simple in-process loops and Hangfire for stored jobs with retries and a dashboard. Use Quartz.NET for complex calendar schedules and clustering, and mix them when you need to. Let our eSignature API tell your jobs when a contract is signed, instead of polling.
A user clicks Place order and sees a confirmation in under a second. Behind that screen, your app still has to reserve stock, take payment, build an invoice PDF and send an email.
Work done inside the web request slows the response and breaks when one step fails. Background jobs move that work out of the request, so the user gets an answer straight away.
This guide compares three common ways to run them in ASP.NET Core, the Microsoft web framework named after Active Server Pages (ASP). Each one comes with setup code.
What are .NET background jobs?
.NET background jobs are work your app does outside the request and response flow. The request queues the work and returns, and a worker finishes it a moment later.
Think of a busy café. The person at the till takes your order and hands you a number, and the kitchen makes the drink. Background jobs in .NET split your app the same way.
Which tasks usually run as background jobs?
- Welcome emails and password reset emails.
- Messages read from Kafka, RabbitMQ or Azure Service Bus.
- Nightly data syncs, imports and reports.
- PDF or Excel exports.
- Cleanup of logs, cache entries and temporary files.
What types of background job are there?
- Fire-and-forget jobs run as soon as possible, such as sending one email.
- Delayed jobs run once after a wait, such as a reminder in 15 minutes.
- Recurring jobs run on a cron schedule, such as every night at 2:00.
- Long-running services loop all the time, such as a message consumer.
Hangfire vs Quartz.NET vs hosted services: how do they compare?
Hosted services are built in and keep nothing on disk, so you write your own storage and retries. Hangfire adds stored jobs, retries and a dashboard, while Quartz.NET adds advanced schedules and clustering.
| Dimension | Hosted services | Hangfire | Quartz.NET |
|---|---|---|---|
| Architecture | In-process background services | In-process workers and a stored job queue | In-process scheduler with stored jobs and triggers |
| Persistence | Your own, for example with Entity Framework Core | Built in, with a database or Redis | Built in, with database job stores |
| Scheduling | Your own timers and loops | Simple calls and cron expressions | Jobs, triggers, calendars and advanced cron |
| Dashboard | None | Hangfire dashboard included | None by default |
| Retries | Your own | Automatic retries built in | Configurable, but you wire them up |
| Clustering | Up to your app | Several servers share one storage | Native clustering support |
| Complexity | Low to medium | Medium | Medium to high |
| Fits | Simple or medium tasks | General job processing | Enterprise schedules and complex time rules |
Quartz vs Hangfire: which scheduler fits your app?
Hangfire fits when your app mostly queues work and people need to see and retry failed jobs. Quartz.NET fits when the timing rules are harder than the job itself.
A Quartz.NET vs Hangfire choice often comes down to one question. Is your hard problem “run this reliably” or “run this at exactly the right moment”? Hangfire answers the first and Quartz.NET the second.
Hangfire vs BackgroundService: when is the built-in option enough?
BackgroundService is enough when losing a run on restart does no harm. Choose Hangfire once a lost job costs money or needs someone to look at it.
A cache warmer that runs every five minutes can simply run again. A payment capture or a signed contract download needs storage and retries, so it belongs in Hangfire.
How do hosted services, Hangfire and Quartz.NET work?
All three run inside a .NET process and start with your app. They differ in what they store, how they schedule and what they show you.
ASP.NET Core hosted services (built in)
ASP.NET Core gives you the IHostedService interface and the BackgroundService base class for background tasks. You register a hosted service in dependency injection (DI), and it starts and stops with your app.
Hosted services need no packages beyond the standard ones and run in the same process as your web app. You own the plumbing, so there is no dashboard or retry logic. They suit queue consumers, token cleanup, cache warmers and heartbeats.
Hangfire (job framework and dashboard)
Hangfire is a framework for background jobs in .NET and ASP.NET Core. It stores jobs in a Structured Query Language (SQL) database such as SQL Server, or in Redis. A web dashboard lets you watch and control them.
Hangfire runs fire-and-forget, delayed, recurring and continuation jobs, with retries and error handling built in. It runs inside your web app or in a separate worker. Teams use it for exports, bulk emails and heavy work moved out of web requests.
Quartz.NET (enterprise scheduler)
Quartz.NET is a scheduling framework ported from the Java Quartz scheduler. It handles complex schedules, calendar rules and clustered schedulers for high availability.
Quartz.NET keeps jobs in a database job store and supports clustering across several nodes. It takes more setup than Hangfire or a plain hosted service. In return, it handles batch workloads and schedules that other tools struggle with.
How do you choose the right background job tool?
Sort your jobs by what a lost run costs, how complex the schedule is and who needs to watch them. Those answers point each job to one tool.
- List every background task you run today and plan to add.
- Mark each one as a simple periodic task, a user-driven job or a strict scheduled job.
- Ask whether losing a job on restart is acceptable, and whether you need automatic retries.
- Check whether your support team needs a screen to view, retry or delete jobs.
- Check how many app instances run, and whether they must share one schedule.
Jobs with real business impact, such as payments, invoices and contracts, need stored jobs and retries. That points to Hangfire or Quartz.NET.
Which tool fits which workload?
- Continuous loops and polling suit a hosted service.
- Cron-style recurring jobs suit Hangfire.
- Business days, holidays, blackout windows and time zones suit Quartz.NET.
- User-triggered jobs that need a dashboard and retries suit Hangfire.
Using more than one tool in the same app is common and normal.
What goes into the implementation plan?
- Where each tool runs: the web app or a separate worker service.
- Which storage it uses, such as a database or Redis.
- How you log, monitor and alert on failed jobs.
- How you roll out cron changes and dashboard security settings.
How do you run a background job in ASP.NET Core with a hosted service?
Write a class that inherits BackgroundService, then register it in Program.cs. The simplest background job ASP.NET Core supports needs no extra packages.
You need an ASP.NET Core app, any services the job uses (such as logging or a DbContext) and some async and await experience.
- Implement a BackgroundService.
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
public class TimedCleanupService : BackgroundService
{
private readonly ILogger _logger;
private readonly TimeSpan _interval = TimeSpan.FromMinutes(5);
public TimedCleanupService(ILogger<TimedCleanupService> logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("TimedCleanupService started.");
while (!stoppingToken.IsCancellationRequested)
{
try
{
// TODO: put your cleanup logic here
_logger.LogInformation("Running cleanup job at: {time}", DateTimeOffset.Now);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while running cleanup job.");
}
await Task.Delay(_interval, stoppingToken);
}
_logger.LogInformation("TimedCleanupService is stopping.");
}
}
- Register it in Program.cs.
var builder = WebApplication.CreateBuilder(args);
// Register hosted service
builder.Services.AddHostedService<TimedCleanupService>();
var app = builder.Build();
app.MapGet("/", () => "Hello World");
app.Run();
The first background job .NET developers write is often a loop like this one. It follows the hosting model in Microsoft’s documentation on background tasks with hosted services.
How to use Hangfire in ASP.NET Core for scheduling tasks
Install the Hangfire packages, point Hangfire at a database or Redis, and add the Hangfire server to your services. You can then enqueue jobs and add recurring ones with a cron expression.
Hangfire in .NET Core and in later .NET versions is set up the same way. You need an ASP.NET Core app, a database or Redis instance and access to NuGet.
- Install packages.
dotnet add package Hangfire
dotnet add package Hangfire.SqlServer
- Configure Hangfire in Program.cs.
using Hangfire;
using Hangfire.SqlServer;
var builder = WebApplication.CreateBuilder(args);
// Hangfire configuration
builder.Services.AddHangfire(config =>
{
config.UseSqlServerStorage( builder.Configuration.GetConnectionString("HangfireConnection"));
});
builder.Services.AddHangfireServer();
var app = builder.Build();
// Dashboard (protect with auth in production)
app.UseHangfireDashboard();
// Simple job
app.MapGet("/enqueue", () =>
{
BackgroundJob.Enqueue(() => Console.WriteLine("Hello from Hangfire!"));
return Results.Ok("Job enqueued.");
});
app.Run();
- Add a recurring job.
RecurringJob.AddOrUpdate(
"nightly-cleanup",
() => Console.WriteLine("Running nightly cleanup..."),
"0 2 * * *" // every day at 02:00 (CRON)
);
The Hangfire .NET Core setup above follows the official Hangfire documentation. You write jobs as plain method calls, and Hangfire stores and schedules them for you.
How do you set up Quartz.NET in ASP.NET Core?
Install the Quartz packages, write a class that implements IJob, and register the job and its trigger in Program.cs. Quartz then runs as a hosted service inside your app.
You need an ASP.NET Core app, access to NuGet and a database when you want stored jobs or clustering.
- Install packages.
dotnet add package Quartz
dotnet add package Quartz.Extensions.Hosting
- Define a job.
using Quartz;
public class ReportJob : IJob
{
public Task Execute(IJobExecutionContext context)
{
Console.WriteLine("Generating report at: " + DateTimeOffset.Now);
// TODO: Generate and persist your report
return Task.CompletedTask;
}
}
- Configure Quartz in Program.cs.
using Quartz;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddQuartz(q =>
{
var jobKey = new JobKey("report-job");
q.AddJob<ReportJob>(opts => opts.WithIdentity(jobKey));
q.AddTrigger(opts => opts
.ForJob(jobKey)
.WithIdentity("report-job-trigger")
.WithCronSchedule("0 0 3 * * ?")); // every day at 03:00
});
// Add Quartz hosted service
builder.Services.AddQuartzHostedService(options =>
{
options.WaitForJobsToComplete = true;
});
var app = builder.Build();
app.MapGet("/", () => "Quartz.NET demo");
app.Run();
The setup matches the Quartz.NET quick-start guide, where you configure the scheduler, jobs and triggers through DI.
When does each background job tool fit in real apps?
Hosted services fit loops tied to the app, Hangfire fits jobs people trigger and watch, and Quartz.NET fits strict schedules. The examples below show where each one earns its place.
Hosted services: continuous and polling workloads
A hosted service suits work that is tied to the app and can restart with it. You accept no dashboard and build your own storage when you need it.
- Checking a queue every 10 seconds, or reading Kafka, RabbitMQ or Azure Service Bus in a loop.
- Polling outside APIs for status updates or scheduled syncs.
- Removing expired tokens, temporary files or stale cache entries.
- Keeping WebSocket relays, SignalR bridges or stream listeners open.
- Heartbeats that update health tables or ping other services.
Hangfire: user-driven and operational jobs
Hangfire suits general job processing where failures must be visible and easy to replay. You get retries, delayed jobs and recurring jobs without writing the plumbing.
- Sending emails, text messages and push notifications.
- Building large reports or exports a user asked for.
- Moving processor-heavy work out of web requests.
- Running a job console where your support team retries failed jobs.
Quartz.NET: enterprise scheduling
Quartz.NET suits systems where scheduling itself is central and must stay available. Its calendars and cron triggers handle rules that simple timers cannot.
- Messages on the last business day of each month at 6:00 in the evening, skipping holidays.
- Enterprise batch jobs and financial calculations.
- Multi-node systems with strict timing targets for each job.
- Multitenant systems with many separate schedules.
What can you use instead of Hangfire in .NET?
The two common Hangfire alternatives are Quartz.NET for complex schedules and a plain hosted service for simple loops. Each one covers a different gap.
The usual Hangfire alternative .NET Core teams pick is Quartz.NET, once their schedules outgrow cron expressions. Teams that drop Hangfire for simplicity move small jobs back into a BackgroundService. Quartz.NET alternatives run the other way: Hangfire for queued work with a dashboard, or a hosted service.
What should you use for multi-step processes that wait days?
Store each process as a record with its current step, and let an event move it forward. A job that sleeps or polls for days is easy to lose on a server restart.
Contract approval is a common case. Your app sends a contract for signature, saves the step as “waiting for signature” and ends the job. BoldSign webhooks then notify your app when document events happen, and your handler enqueues the next job.
Our guide to downloading signed documents with webhook callbacks shows that pattern end to end.
How do you keep background jobs reliable in production?
Keep controllers quick, make every job safe to run twice and store jobs somewhere that survives a restart. Then watch them, so a stuck worker gets noticed.
How should you write each job?
- Enqueue work in the controller and return straight away.
- Make jobs idempotent, so a retry or a double trigger leaves data correct.
- Use async all the way down, and avoid blocking calls such as
Task.Resultand.Wait(). - Honor the
CancellationTokenin hosted services so they shut down cleanly.
How should you run and watch jobs?
- Use SQL Server or Redis job stores in production, and keep in-memory storage for local development.
- Catch and log errors in hosted service loops, and use Hangfire filters or Quartz.NET listeners.
- Track job duration, failures and queue length in your logs and monitoring tools.
- Turn on the graceful stop options in the Quartz.NET hosted service and the Hangfire server.
- Put authentication in front of the Hangfire dashboard and any other admin screen.
What mistakes break .NET background jobs?
Most failures come from long work in the web request, missing retries and memory-only queues. Scale-out adds duplicate runs when every instance fires the same timer.
Which design mistakes cause lost or failed jobs?
- Running long tasks in the web request, which leads to timeouts and exhausted resources.
- Using
Task.Runeverywhere, which leaves work unstructured and hard to monitor. - Skipping retries and idempotency on email or payment jobs.
- Keeping the job queue only in memory, so a restart loses it.
Which operational mistakes cause duplicate or silent jobs?
- Timer-based hosted services that run on every instance after you scale out.
- Cron expressions such as
0 0 3 * * ?left without a comment saying what they mean. - Workers that stop quietly, with no health endpoint or alert to catch them.
A distributed lock, or moving the schedule to a single node or framework, fixes the first problem.
Where should you host .NET background jobs?
Host them anywhere your .NET process stays running all the time, such as a virtual machine, a container or a Windows or Linux service. Web hosts that unload idle apps also stop the jobs inside them.
The top platforms for background job hosting share that one trait: the process stays up. For heavy or critical jobs, run Hangfire or Quartz.NET in a separate worker service, apart from your public web app.
Which BoldSign plan do you need to use API webhooks in production?
Live API calls and webhooks need the Enterprise API plan, which starts at $30 a month with 40 envelopes. Prices are in USD, as listed on the BoldSign pricing page in November 2026.
Every other plan gives you sandbox access to the API only. The sandbox is free, so you can build and test your webhook handler and jobs before you go live.
How do you start building event-driven background jobs?
Start small: one job, one webhook and a sandbox where mistakes cost nothing. Then add retries and monitoring as the job grows.
- Create a free API sandbox account and wire a webhook to a background job.
- Request a demo to talk through your integration with our team.
- Visit our support portal with a question about your setup.
Frequently asked questions
What's the simplest way to run background jobs in ASP.NET Core?
A hosted service built on BackgroundService is the simplest option. It ships with ASP.NET Core, needs no extra packages and suits timer loops and queue consumers.
Is Hangfire overkill for small projects?
Usually not. Setup takes a few lines, and the dashboard and retries save time even in small apps. A single simple timer is the case where a hosted service is enough.
When should I prefer Quartz.NET over Hangfire?
Pick Quartz.NET when the schedule itself is the hard part: complex cron expressions, holiday calendars and clustered schedulers. Pick Hangfire when you mostly queue work and want a dashboard.
Can I use hosted services and Hangfire together?
Yes. A common pattern is a hosted service that reads a queue such as Kafka in a loop and enqueues a Hangfire job for each message.
How should a growing company compare available options for background worker design?
List every job, then sort them by how much a lost job costs, how complex the schedule is and who needs to see failures. Those three answers point to a hosted service, Hangfire or Quartz.NET.
I need to run background jobs - what hosting supports this easily?
Any host that keeps your .NET process running all the time works: a virtual machine, a container or a Windows or Linux service. Avoid hosts that unload idle web apps, because in-process jobs stop with them.
How do I avoid duplicate jobs when scaling out my app?
Hangfire and Quartz.NET handle this when every server shares the same job storage. With hosted services, use a distributed lock or run the schedule in one worker process only.
Can I run these schedulers in a separate worker service?
Yes. Hosted services, Hangfire servers and Quartz.NET schedulers all run in a worker process or container, apart from your public web app.