Neoxack.Hangfire.Mutex 0.1.0

dotnet add package Neoxack.Hangfire.Mutex --version 0.1.0
NuGet\Install-Package Neoxack.Hangfire.Mutex -Version 0.1.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="Neoxack.Hangfire.Mutex" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Neoxack.Hangfire.Mutex --version 0.1.0
#r "nuget: Neoxack.Hangfire.Mutex, 0.1.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.
// Install Neoxack.Hangfire.Mutex as a Cake Addin
#addin nuget:?package=Neoxack.Hangfire.Mutex&version=0.1.0

// Install Neoxack.Hangfire.Mutex as a Cake Tool
#tool nuget:?package=Neoxack.Hangfire.Mutex&version=0.1.0

Hangfire.Mutex

Mutex prevents concurrent execution of multiple background jobs that share the same resource identifier. All we need is to decorate our background job methods with the MutexAttribute filter and define what resource identifier should be used.

[Mutex("my-resource")]
public void MyMethod()
{
    // ...
}

We can also create multiple background job methods that share the same resource identifier, and mutual exclusive behavior will span all of them, regardless of the method name.

[Mutex("my-resource")]
public void FirstMethod() { /* ... */ }

[Mutex("my-resource")]
public void SecondMethod() { /* ... */ }

Since mutexes are created dynamically, it’s possible to use a dynamic resource identifier based on background job arguments. To define it, we should use String.Format-like templates, and during invocation all the placeholders will be replaced with actual job arguments. But ensure everything is lower-cased and contains only alphanumeric characters with limited punctuation – no rules except maximum length and case insensitivity is enforced, but it’s better to keep identifiers simple.

[Mutex("orders:{0}")]
public void ProcessOrder(long orderId) { /* ... */ }

[Mutex("newsletters:{0}:{1}")]
public void ProcessNewsletter(int tenantId, long newsletterId) { /* ... */ }
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
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
0.1.0 102 2/13/2024