Pandax.Hangfire.Mutexes 1.0.0

dotnet add package Pandax.Hangfire.Mutexes --version 1.0.0
                    
NuGet\Install-Package Pandax.Hangfire.Mutexes -Version 1.0.0
                    
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="Pandax.Hangfire.Mutexes" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pandax.Hangfire.Mutexes" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Pandax.Hangfire.Mutexes" />
                    
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 Pandax.Hangfire.Mutexes --version 1.0.0
                    
#r "nuget: Pandax.Hangfire.Mutexes, 1.0.0"
                    
#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 Pandax.Hangfire.Mutexes@1.0.0
                    
#: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=Pandax.Hangfire.Mutexes&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Pandax.Hangfire.Mutexes&version=1.0.0
                    
Install as a Cake Tool

Pandax.Hangfire.Mutexes

实现Hangfire互斥锁功能,保证同一个任务不会并行运行

如果通过接口注入任务,则特性标记在接口方法上,实现类则不需要标记了

// 通过接口注册job实现
builder.Services.AddScoped<IMyJob, MyTestJob>();

public interface IMyJob
{
    [Mutex("myJob-{0}")] // 串行任务
    Task TodoAsync(string jobName, CancellationToken cancellationToken);
}

public class MyTestJob(ILogger<MyTestJob> logger) : IMyJob
{
    public async Task TodoAsync(string jobName, CancellationToken cancellationToken)
    {
        throw new NotImplementedException();
    } 
}

不通过接口注入则标记在实现类方法上

// 直接注册job实现
builder.Services.AddScoped<MyTestJob>();

public class MyTestJob(ILogger<MyTestJob> logger) : IMyJob
{
    [Mutex("myJob-{0}")] // 串行任务
    public async Task TodoAsync(string jobName, CancellationToken cancellationToken)
    {
        throw new NotImplementedException();
    }
}
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on Pandax.Hangfire.Mutexes:

Package Downloads
MyJob.Shared

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 258 6/13/2025