New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

MiniMutex

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

MiniMutex

Lightweight helper to claim named mutexes so you can gate, block, or unlock single-instance apps.

nugetNuGet
Version
1.2.4
Version published
Total downloads
4.6K
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 04 Dec 2025

Related posts