What is Hangfire?
Hangfire is a comprehensive background job processing framework designed specifically for .NET and .NET Core applications. It enables developers to execute various types of background jobs—including fire-and-forget, delayed, recurring, continuations, and batches—without requiring Windows Services or separate processes. The framework ensures job persistence through supported storages like SQL Server and Redis, allowing applications to restart safely without losing job data.
With built-in features such as a web interface for monitoring, support for popular logging frameworks, automatic retries on failures, and distributed processing capabilities, Hangfire offers a reliable and efficient solution for handling background tasks. It is open-source under the LGPLv3 license, making it free for commercial use, while optional Pro and Enterprise subscriptions provide additional functionality and dedicated support.
Features
- Fire-and-Forget Jobs: Execute jobs once immediately after creation
- Delayed Jobs: Schedule jobs to run once after a specified time interval
- Recurring Jobs: Run jobs repeatedly based on CRON schedules
- Continuations: Execute jobs after parent jobs finish
- Batches: Create groups of jobs as single entities with atomic creation
- Persistent Storage: Store jobs in SQL Server, Redis, or other storages for reliability
- Web Interface: Monitor background processing and job states through built-in dashboard
- Automatic Retries: Re-try failed jobs automatically on unhandled exceptions or application termination
- Distributed Processing: Run jobs across different machines with automatic synchronization
- Extensible Architecture: Customize processing with job filters and implement support for additional storages
Use Cases
- Processing email notifications asynchronously in web applications
- Scheduling periodic data cleanup or report generation tasks
- Handling long-running computations without blocking user requests
- Managing batch operations like image processing or file conversions
- Implementing retry logic for failed external API calls
- Distributing workloads across multiple servers for scalability
- Monitoring job progress and errors through a centralized dashboard
FAQs
-
What is the difference between Hangfire Core and Hangfire Pro?
Hangfire Core is the open-source version under LGPL license, free for commercial use with basic features. Hangfire Pro is a paid extension offering additional functionality like advanced storage options and dedicated support under a commercial EULA. -
How does Hangfire handle application restarts or failures?
Hangfire uses persistent storage to save job data, so jobs survive application restarts, pool recycles, or crashes, and are automatically re-tried if failures occur. -
Can I use Hangfire with ASP.NET applications?
Yes, Hangfire is designed to work seamlessly with ASP.NET and .NET Core applications, handling background processing without requiring separate services. -
What types of background jobs does Hangfire support?
Hangfire supports fire-and-forget, delayed, recurring, continuation, and batch jobs, allowing flexible scheduling and execution. -
Is there a free trial for Hangfire Pro?
No, there is no free trial, but purchases include a 30-day money-back guarantee for dissatisfaction.