AzureMutex 1.1.0

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

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

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)


Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
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.1.0 2,348 2/6/2022
1.0.0 344 1/3/2022