AzureMutex 1.2.1-prerelease

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

// Install AzureMutex as a Cake Tool
#tool nuget:?package=AzureMutex&version=1.2.1-prerelease&prerelease                

Distributed mutex based on Azure Blobs

CI NuGet

.Net implementation of a distributed lock on top of Azure Blobs.

Diclaimer: if you think you need it, you might doing it wrong 😃

Jokes aside, we do use it for some cases. Typical example involves a process running on several nodes (for redundancy). E.g. periodic sync with a 3rd party system, a database migration, etc.

Recommended usage is via an extension method that takes a long-running task as a parameter and ensures it runs as a single instance (in a single process):

var mutex = new BlobMutex("storage-account-connection", "mutex-container", "blob-name");

// 1. Blocks until lock is held or `CancellationToken` cancelled
// 2. Executes `LongRunningTask` while periodically renewing the lock taken. 
// 3. Runs either until operation is finished or `CancellationToken` canceled
// 4. Terminates operation in case the lock is lost (e.g. because of connectivity issues)
//    with a `LeaseLostException`
await mutex.RunSingleInstance(LongRunningTask, CancellationToken.None); 

async Task LongRunningTask(CancellationToken cancellation) {
    do {
        await Task.Delay(TimeSpan.FromMinutes(10), cancellation);
    }
    while (!cancellation.IsCancellationRequested)
}

References

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 is compatible.  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
1.2.1-prerelease 117 1/26/2024
1.2.0 4,696 1/25/2024
1.1.0 7,318 2/6/2022
1.0.0 454 1/3/2022