MiniMutex 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MiniMutex --version 1.1.0
                    
NuGet\Install-Package MiniMutex -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="MiniMutex" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MiniMutex" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MiniMutex" />
                    
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 MiniMutex --version 1.1.0
                    
#r "nuget: MiniMutex, 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.
#:package MiniMutex@1.1.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=MiniMutex&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=MiniMutex&version=1.1.0
                    
Install as a Cake Tool

MiniMutex

MiniMutex is a lightweight, zero-dependency helper for safely claiming named mutexes.
Use it to gate, block, or unlock single-instance apps and coordinated worker processes.
Targets .NET 6+.


🚀 Features

  • Single-instance application enforcement
  • Named mutex claiming with configurable behavior
  • Optional waiting (block, timeout, or no-wait)
  • Global namespaces for cross-session mutexes
  • Robust abandoned mutex handling
  • Disposable mutex handles
  • Manager for tracking multiple claims
  • Safe defaults with MiniMutexGate.Init()

📦 Installation

dotnet add package MiniMutex

Or via the NuGet package manager:

Install-Package MiniMutex

🧭 Usage

Claim a mutex

using MiniMutex;

// Claim a mutex (global makes it visible across user sessions)
if (MiniMutexGate.TryClaim("my-app-single-instance",
    out var handle,
    new MiniMutexOptions { UseGlobalNamespace = true }))
{
    // You own the mutex while the handle lives
    // ... launch a guarded app, gate a critical section, etc.
    handle.Dispose(); // or using var handle = ...
}

Manage multiple claims together

using var manager = new MiniMutexManager();

if (manager.TryClaim("worker-1", out _)
    && manager.TryClaim("worker-2", out _))
{
    // Work while both locks are held
}

manager.ReleaseAll();

⚙️ Set reusable defaults

MiniMutexGate.Init(new MiniMutexOptions
{
    UseGlobalNamespace = true,
    WaitForExisting = TimeSpan.FromSeconds(2),
});

// All future TryClaim calls without explicit options use defaults
MiniMutexGate.TryClaim("shared-job", out _);

🔧 Options Overview

MiniMutexOptions lets you configure:

  • InitiallyOwned – own immediately on creation
  • WaitForExisting – timeout for existing locks
  • UseGlobalNamespace – cross-session mutex support
  • AllowAbandoned – treat abandoned mutexes as success
  • ReleaseOnDispose – auto-release on Dispose()
  • ExitContext – call WaitOne with synchronization context exit

📜 License

MiniMutex is licensed under the MIT License.

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.  net9.0 was computed.  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.
  • net6.0

    • No dependencies.

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.3 185 11/26/2025
1.2.2 167 11/26/2025
1.2.0 170 11/26/2025
1.1.0 180 11/26/2025