MiniMutex 1.2.3
dotnet add package MiniMutex --version 1.2.3
NuGet\Install-Package MiniMutex -Version 1.2.3
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.2.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MiniMutex" Version="1.2.3" />
<PackageReference Include="MiniMutex" />
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.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MiniMutex, 1.2.3"
#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.2.3
#: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.2.3
#tool nuget:?package=MiniMutex&version=1.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net7.0-windows7.0 is compatible. net8.0-windows was computed. net8.0-windows7.0 is compatible. net9.0-windows 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-windows7.0
- No dependencies.
-
net7.0-windows7.0
- No dependencies.
-
net8.0-windows7.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.