Skip to content

Background jobs

Work that shouldn't block a request — sending email, delivering webhooks, nightly cleanup — runs as a background job on Hangfire, with a dashboard to watch it.

One-off jobs

Enqueue work to run off the request path:

csharp
_jobs.Enqueue(() => InvoiceJob.GenerateAsync(orderId));

The request returns immediately; the job runs on the job server with its own retries.

Recurring jobs

Annotate a static method with a cron expression and it's scheduled automatically at startup — no central registration:

csharp
[RecurringJob("0 3 * * *")]            // every day at 03:00
public static async Task PurgeOldNotificationsAsync()
{
    using var scope = JobServices.Provider.CreateScope();
    // … resolve services and do the work
}

Dashboard

The Hangfire dashboard is available at /hangfire in development — inspect queued, processing, succeeded, and failed jobs, and retry by hand. The job store is configurable (SQLite by default, your production database when you scale out).

Several built-in features run on this: webhook delivery + retries, notification email copies, and notification retention. The recipe is Add a background job.

Community edition

Background jobs ship whenever a feature that needs them (notifications, webhooks, the demo) is included. A lean Community scaffold without those omits Hangfire. See Editions.

NetForge Community is MIT-licensed. Pro is a commercial edition.