Zongsoft.Externals.Hangfire 2.9.1

dotnet add package Zongsoft.Externals.Hangfire --version 2.9.1
                    
NuGet\Install-Package Zongsoft.Externals.Hangfire -Version 2.9.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zongsoft.Externals.Hangfire" Version="2.9.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zongsoft.Externals.Hangfire" Version="2.9.1" />
                    
Directory.Packages.props
<PackageReference Include="Zongsoft.Externals.Hangfire" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zongsoft.Externals.Hangfire --version 2.9.1
                    
#r "nuget: Zongsoft.Externals.Hangfire, 2.9.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zongsoft.Externals.Hangfire@2.9.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zongsoft.Externals.Hangfire&version=2.9.1
                    
Install as a Cake Addin
#tool nuget:?package=Zongsoft.Externals.Hangfire&version=2.9.1
                    
Install as a Cake Tool

Zongsoft.Externals.Hangfire Extension Plugin Library

License NuGet Version NuGet Downloads GitHub Stars

English | 简体中文


Overview

Zongsoft.Externals.Hangfire adapts Hangfire to the Zongsoft scheduling abstractions. It provides:

  • IScheduler<TriggerOptions.Cron> for recurring jobs driven by Cron expressions.
  • IScheduler<TriggerOptions.Latency> for one-off jobs executed after a delay.
  • A background Server worker that dispatches jobs to Zongsoft IHandler instances.
  • Optional Redis storage and ASP.NET Core Dashboard integration.

The library targets .NET 8, .NET 9, and .NET 10. Hangfire storage must be configured before the scheduler or server starts.

Packages

Package Purpose
Zongsoft.Externals.Hangfire Core scheduler and background server integration.
Zongsoft.Externals.Hangfire.Storages.Redis Hangfire storage backed by Zongsoft.Externals.Redis.
Zongsoft.Externals.Hangfire.Web Registers Hangfire services and maps the Dashboard in a Zongsoft web application.

Install the packages required by the host:

dotnet add package Zongsoft.Externals.Hangfire
dotnet add package Zongsoft.Externals.Hangfire.Storages.Redis
dotnet add package Zongsoft.Externals.Hangfire.Web

Plugin setup

Load Zongsoft.Externals.Hangfire.plugin to register the schedulers. A daemon host should also load Zongsoft.Externals.Hangfire-daemon.plugin; it creates and starts the background server and exposes /Workbench/Scheduler/Handlers as the handler registration point.

Choose and configure exactly one Hangfire JobStorage. The Redis adapter is available through Zongsoft.Externals.Hangfire.Storages.Redis.plugin and uses the Hangfire connection setting from the Zongsoft Redis settings provider.

Server configuration

The server reads options from Externals/Hangfire/Server. The packaged defaults set the schedule polling interval to 10 seconds:

<options>
	<option path="Externals/Hangfire">
		<server scheduleInterval="10s" />
	</option>
</options>

Supported server attributes:

Attribute Description
queues Queue names processed by this server.
workerCount Number of concurrent Hangfire workers.
stopTimeout Grace period when stopping the server.
shutdownTimeout Maximum server shutdown duration.
scheduleInterval Polling interval for scheduled jobs.
heartbeatInterval Interval between server heartbeats.
checkInterval Interval used to check inactive servers.
serverTimeout Time after which a server is considered inactive.

Only positive numeric or duration values override Hangfire defaults. When the worker is named something other than Server, its Hangfire server name is emitted as <worker-name>@<machine-name>.

Register a handler

Jobs are addressed by handler name. Implement IHandler (usually by deriving from HandlerBase<TArgument>) and register the instance under /Workbench/Scheduler/Handlers:

using System;
using System.Threading;
using System.Threading.Tasks;

using Zongsoft.Components;
using Zongsoft.Collections;

public sealed class ReportHandler : HandlerBase<int>
{
	protected override ValueTask OnHandleAsync(
		int reportId,
		Parameters parameters,
		CancellationToken cancellation)
	{
		Console.WriteLine($"Generating report {reportId}.");
		return ValueTask.CompletedTask;
	}
}
<extension path="/Workbench/Scheduler/Handlers">
	<object name="Report" type="Example.ReportHandler, Example" />
</extension>

Every running Hangfire Server whose handler collection contains Report receives the dispatched job. Keep handler names stable because persisted Hangfire jobs store that name.

Schedule jobs

Resolve or inject the typed scheduler that matches the trigger mode:

using System;
using System.Threading;
using System.Threading.Tasks;

using Zongsoft.Scheduling;

public sealed class ReportScheduler(IScheduler<TriggerOptions.Cron> cron,
	IScheduler<TriggerOptions.Latency> latency)
{
	public ValueTask<string> ScheduleDailyAsync(CancellationToken cancellation = default) =>
		cron.ScheduleAsync(
			"Report",
			42,
			new TriggerOptions.Cron("daily-report", "0 2 * * *", TimeZoneInfo.Utc),
			cancellation);

	public ValueTask<string> ScheduleOnceAsync(CancellationToken cancellation = default) =>
		latency.ScheduleAsync(
			"Report",
			42,
			new TriggerOptions.Latency(TimeSpan.FromMinutes(5)),
			cancellation);
}

The returned string is the Hangfire job identifier. Use RescheduleAsync(identifier) to trigger it again and UnscheduleAsync(identifier) to remove it.

Command integration

The generic Scheduler, Schedule, Reschedule, and Unschedule commands are provided by the Zongsoft.Commands package under Zongsoft.Scheduling.Commands. Load Zongsoft.Commands.plugin when command-line scheduling is required; the Hangfire package itself no longer owns those commands.

Web Dashboard

Loading Zongsoft.Externals.Hangfire.Web.plugin registers Hangfire with the ASP.NET Core host and calls UseHangfireDashboard() during application initialization. Configure Dashboard authorization and routing according to the security requirements of the hosting application; do not expose the Dashboard publicly without access controls.

Samples

See the sample project for a minimal handler plugin. Storage-specific and web-specific projects are available under storages and web.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.9.1 76 8/11/2026
2.8.0 160 1/11/2026
2.7.0 132 12/31/2025
2.6.0 188 10/10/2025
2.5.0 290 8/28/2025
2.4.0 409 7/21/2025
2.3.0 230 5/30/2025
2.2.2 309 5/16/2025
2.2.1 221 5/9/2025
2.2.0 223 5/6/2025
2.1.0 254 4/28/2025
2.0.0 206 2/24/2025
Loading failed