HMBSbige.SingleInstance 7.0.0

dotnet add package HMBSbige.SingleInstance --version 7.0.0
                    
NuGet\Install-Package HMBSbige.SingleInstance -Version 7.0.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="HMBSbige.SingleInstance" Version="7.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HMBSbige.SingleInstance" Version="7.0.0" />
                    
Directory.Packages.props
<PackageReference Include="HMBSbige.SingleInstance" />
                    
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 HMBSbige.SingleInstance --version 7.0.0
                    
#r "nuget: HMBSbige.SingleInstance, 7.0.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 HMBSbige.SingleInstance@7.0.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=HMBSbige.SingleInstance&version=7.0.0
                    
Install as a Cake Addin
#tool nuget:?package=HMBSbige.SingleInstance&version=7.0.0
                    
Install as a Cake Tool

SingleInstance

NuGet

A .NET 10 library that elects one application instance and lets later instances notify it with simple integer commands over named pipes.

Usage

using SingleInstance;

await using SingleInstanceService instance = new("MyApplication");

if (!instance.IsFirstInstance)
{
	await instance.SendMessageAsync((int)AppCommand.Activate);
	return;
}

instance.StartListening(static command => HandleCommand((AppCommand)command));

// Continue into the application's normal run loop.
// Observe instance.ListenerCompletion to detect listener failures.

static void HandleCommand(AppCommand command)
{
	// Handle the command on the first instance.
}

enum AppCommand
{
	Activate = 1,
	ShowMainWindow = 2,
}

Notes

  • Use the same short, preferably ASCII, identifier in every instance; do not vary its casing or namespace prefix. Long identifiers can exceed Unix socket-path limits.
  • The message handler must be synchronous. Do not pass an async lambda; synchronous handler exceptions are ignored, so catch and log them inside the handler.
  • StartListening reports initial setup failures directly; observe ListenerCompletion for failures after startup.
  • SendMessageAsync throws TimeoutException if it cannot connect within 10 seconds; use a CancellationToken for an earlier deadline.
  • In UI applications, prefer await using. Synchronous Dispose() waits for the listener and active handler and can deadlock if the handler depends on the disposing thread.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on HMBSbige.SingleInstance:

Repository Stars
netchx/netch
A simple proxy client
HMBSbige/ShadowsocksR-Windows
Ship of Theseus
HMBSbige/BilibiliLiveRecordDownLoader
Bilibili 直播录制
ME3Tweaks/LegendaryExplorer
Editor toolset for Mass Effect Trilogy and Mass Effect Legendary Edition
Version Downloads Last Updated
7.0.0 188 7/28/2026
6.0.1 13,345 6/11/2023
6.0.1-rc.1 358 12/15/2021
6.0.0 14,038 11/9/2021
5.1.0-alpha.2 524 7/16/2021
5.1.0-alpha 1,277 7/15/2021
5.0.7 10,579 7/13/2021
5.0.0 9,038 11/13/2020
1.1.0 1,885 10/30/2020
1.0.3 1,525 10/28/2020
1.0.2 1,531 10/22/2020
1.0.1 1,566 10/22/2020
1.0.0 1,566 10/22/2020