Hangfire
Background job processing library for .NET — runs background jobs, delayed tasks, and recurring schedules within ASP.NET applications with persistent storage. Hangfire features: BackgroundJob.Enqueue(() => ProcessAgent(agentId)) for fire-and-forget, BackgroundJob.Schedule(() => SendReport(agentId), TimeSpan.FromHours(1)) for delayed jobs, RecurringJob.AddOrUpdate("daily-sync", () => SyncAgents(), Cron.Daily) for recurring, and job continuations (BackgroundJob.ContinueJobWith). Built-in web dashboard at /hangfire showing job queues, history, and retry. Persistent storage: SQL Server, PostgreSQL (Hangfire.PostgreSql), Redis, MongoDB. Automatic retry with exponential backoff. No separate worker process needed — runs in-process with ASP.NET.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Protect Hangfire dashboard with authentication — unprotected dashboard exposes agent job arguments (potentially containing sensitive data) and allows unauthorized job manipulation. Job arguments stored in DB may contain agent data — use IDs not full objects. Enable TLS for storage connection.
⚡ Reliability
Best When
You're building an ASP.NET agent application that needs background processing, recurring jobs, and delayed tasks without running separate worker processes — Hangfire handles the complete job lifecycle with built-in monitoring.
Avoid When
You need sub-second scheduling precision, you require independent scaling of job workers from web servers, or you're building complex stateful agent workflow orchestration.
Use Cases
- • Agent background task processing — BackgroundJob.Enqueue<AgentProcessor>(x => x.ProcessTask(taskId)) fires off agent task processing without blocking HTTP response; Hangfire processes in background thread pool
- • Scheduled agent report generation — RecurringJob.AddOrUpdate("agent-weekly-report", () => GenerateWeeklyReport(), "0 8 * * MON") runs agent analytics every Monday at 08:00 using Cron expression
- • Delayed agent notification — BackgroundJob.Schedule(() => SendAgentAlert(agentId, alertType), TimeSpan.FromMinutes(30)) sends delayed notification 30 minutes after agent event without timer infrastructure
- • Agent job workflow with continuations — var jobId = BackgroundJob.Enqueue(() => AnalyzeAgent(id)); BackgroundJob.ContinueJobWith(jobId, () => NotifyCompletion(id)) chains agent analysis with notification on completion
- • Hangfire dashboard for agent job monitoring — app.UseHangfireDashboard('/hangfire', opts) provides real-time dashboard showing queued, processing, succeeded, and failed agent jobs with manual retry capability
Not For
- • Microservices with dedicated workers — Hangfire in-process model couples job processing to web process; for agent microservices requiring independent scaling of job workers, use dedicated worker services with Azure Service Bus or RabbitMQ
- • Sub-second job scheduling — Hangfire polls storage (default 15 seconds); for agent tasks requiring second-level precision, use in-memory schedulers or timer-based triggers
- • Stateful multi-step agent workflows — Hangfire handles fire-and-forget and simple continuations; for complex agent workflows with compensation and sagas, use Temporal or MassTransit Sagas
Interface
Authentication
No external auth. Hangfire dashboard should be protected: UseHangfireDashboard('/hangfire', new DashboardOptions { Authorization = new[] { new HangfireAuthFilter() } }). Storage connection uses application's DB credentials.
Pricing
Open source Hangfire is LGPL and free. Hangfire Pro commercial license adds batch jobs, continuations, and ACL features useful for enterprise agent platforms.
Agent Metadata
Known Gotchas
- ⚠ Job method must be public and non-generic — Hangfire serializes job method reference by type/method name; private methods, generic methods, and lambda capture variables (closures) are not serializable; use public static or instance methods with simple parameters for agent background jobs; closures cause Hangfire deserialization errors on job execution
- ⚠ Job arguments must be JSON-serializable — Hangfire serializes arguments to JSON in storage; IEnumerable, complex objects, and EF Core entities with circular references cause JSON serialization failures; always pass IDs (agentId) not entities to Hangfire agent job methods
- ⚠ Scope lifetime: DI injection requires services registered with correct lifetime — Hangfire creates new scope per job; IScoped services work correctly; ISingleton services shared across jobs (watch for thread safety in agent services); injecting IHttpContextAccessor in Hangfire job is null (no HTTP context in background jobs)
- ⚠ Dashboard must be secured in production — Hangfire dashboard has no auth by default; exposes all job history, arguments (potentially sensitive agent data), and allows manual job triggering; implement IDashboardAuthorizationFilter requiring admin role for agent platform production deployments
- ⚠ RecurringJob.AddOrUpdate is idempotent but timezone matters — AddOrUpdate called on startup updates existing recurring job; Cron expressions evaluated in UTC by default; RecurringJobOptions { TimeZone = TimeZoneInfo.FindSystemTimeZoneById('Eastern Standard Time') } for timezone-aware agent scheduled jobs; wrong timezone causes jobs to run at unexpected times
- ⚠ UseHangfireServer in web process affects app shutdown — app.UseHangfireServer() starts background job server in web process; IIS recycling or app restart waits for in-progress agent jobs to complete (graceful shutdown); set BackgroundJobServerOptions.ShutdownTimeout to limit max wait during agent service deployments
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for Hangfire.
Scores are editorial opinions as of 2026-03-06.