ktsu.SingleAppInstance
1.3.46
Prefix Reserved
dotnet add package ktsu.SingleAppInstance --version 1.3.46
NuGet\Install-Package ktsu.SingleAppInstance -Version 1.3.46
<PackageReference Include="ktsu.SingleAppInstance" Version="1.3.46" />
<PackageVersion Include="ktsu.SingleAppInstance" Version="1.3.46" />
<PackageReference Include="ktsu.SingleAppInstance" />
paket add ktsu.SingleAppInstance --version 1.3.46
#r "nuget: ktsu.SingleAppInstance, 1.3.46"
#:package ktsu.SingleAppInstance@1.3.46
#addin nuget:?package=ktsu.SingleAppInstance&version=1.3.46
#tool nuget:?package=ktsu.SingleAppInstance&version=1.3.46
ktsu.SingleAppInstance
A .NET library that ensures only one instance of your application is running at a time.
Introduction
ktsu.SingleAppInstance is a lightweight .NET library that provides a robust mechanism to ensure only one instance of an application is running at a time. It uses a JSON-serialized PID file with multi-attribute process verification to accurately detect running instances, making it ideal for desktop applications, services, or any software that requires instance exclusivity to prevent resource conflicts or maintain data integrity.
Features
- Single Instance Enforcement: Prevents multiple copies of your application from running simultaneously
- Enhanced Process Identification: Verifies running instances using multiple attributes (PID, process name, start time, executable path) for accurate detection
- Race Condition Handling: Includes a built-in 1-second delay to safely detect simultaneous startup attempts
- PID File Management: Stores process information as JSON in the application data directory
- Backward Compatibility: Gracefully handles legacy PID files that stored only a plain integer PID
- Simple API: Two methods —
ExitIfAlreadyRunning()for automatic exit andShouldLaunch()for custom logic - Multi-Target Support: Works across .NET 10.0 through .NET 5.0, .NET Standard 2.0/2.1
Installation
Package Manager Console
Install-Package ktsu.SingleAppInstance
.NET CLI
dotnet add package ktsu.SingleAppInstance
Package Reference
<PackageReference Include="ktsu.SingleAppInstance" Version="x.y.z" />
Usage Examples
Basic Example
The simplest way to use SingleAppInstance is to call ExitIfAlreadyRunning at the start of your application. If another instance is detected, the process exits automatically:
using ktsu.SingleAppInstance;
class Program
{
static void Main(string[] args)
{
SingleAppInstance.ExitIfAlreadyRunning();
// Your application code here
Console.WriteLine("Application is running.");
}
}
Custom Launch Logic
If you prefer to handle the duplicate-instance case yourself, use ShouldLaunch() which returns a boolean:
using ktsu.SingleAppInstance;
class Program
{
static void Main(string[] args)
{
if (SingleAppInstance.ShouldLaunch())
{
// Your application code here
Console.WriteLine("Application is running.");
}
else
{
Console.WriteLine("Another instance is already running.");
}
}
}
WPF Application Integration
using System.Windows;
using ktsu.SingleAppInstance;
namespace MyWpfApp
{
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (!SingleAppInstance.ShouldLaunch())
{
MessageBox.Show("Application is already running.");
Shutdown();
return;
}
MainWindow = new MainWindow();
MainWindow.Show();
}
}
}
API Reference
SingleAppInstance
A static class that provides single-instance enforcement for applications. Uses a PID file stored in the application data directory to track running instances.
Methods
| Name | Return Type | Description |
|---|---|---|
ExitIfAlreadyRunning() |
void |
Checks if another instance is running and calls Environment.Exit(0) if so |
ShouldLaunch() |
bool |
Writes a PID file, waits 1 second for race condition detection, and returns true if safe to proceed |
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
License
This project is licensed under the MIT License. See the LICENSE.md file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. 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 is compatible. 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 is compatible. 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 is compatible. 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 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- ktsu.AppDataStorage (>= 1.16.37)
- ktsu.Semantics.Paths (>= 3.0.1)
- ktsu.Semantics.Strings (>= 3.0.1)
- System.Memory (>= 4.6.3)
- System.Text.Json (>= 10.0.11)
- System.Threading.Tasks.Extensions (>= 4.6.3)
-
.NETStandard 2.1
- ktsu.AppDataStorage (>= 1.16.37)
- ktsu.Semantics.Paths (>= 3.0.1)
- ktsu.Semantics.Strings (>= 3.0.1)
- System.Text.Json (>= 10.0.11)
-
net10.0
- ktsu.AppDataStorage (>= 1.16.37)
- ktsu.Semantics.Paths (>= 3.0.1)
- ktsu.Semantics.Strings (>= 3.0.1)
-
net5.0
- ktsu.AppDataStorage (>= 1.16.37)
- ktsu.Semantics.Paths (>= 3.0.1)
- ktsu.Semantics.Strings (>= 3.0.1)
- System.Text.Json (>= 10.0.11)
-
net6.0
- ktsu.AppDataStorage (>= 1.16.37)
- ktsu.Semantics.Paths (>= 3.0.1)
- ktsu.Semantics.Strings (>= 3.0.1)
- System.Text.Json (>= 10.0.11)
-
net7.0
- ktsu.AppDataStorage (>= 1.16.37)
- ktsu.Semantics.Paths (>= 3.0.1)
- ktsu.Semantics.Strings (>= 3.0.1)
- System.Text.Json (>= 10.0.11)
-
net8.0
- ktsu.AppDataStorage (>= 1.16.37)
- ktsu.Semantics.Paths (>= 3.0.1)
- ktsu.Semantics.Strings (>= 3.0.1)
- System.Text.Json (>= 10.0.11)
-
net9.0
- ktsu.AppDataStorage (>= 1.16.37)
- ktsu.Semantics.Paths (>= 3.0.1)
- ktsu.Semantics.Strings (>= 3.0.1)
- System.Text.Json (>= 10.0.11)
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.3.46 | 50 | 8/19/2026 |
| 1.3.45 | 54 | 8/18/2026 |
| 1.3.44 | 72 | 8/17/2026 |
| 1.3.43 | 183 | 7/8/2026 |
| 1.3.42 | 125 | 7/7/2026 |
| 1.3.41 | 126 | 7/6/2026 |
| 1.3.40 | 124 | 7/3/2026 |
| 1.3.39 | 137 | 7/2/2026 |
| 1.3.38 | 120 | 7/1/2026 |
| 1.3.37 | 130 | 6/30/2026 |
| 1.3.36 | 131 | 6/29/2026 |
| 1.3.35 | 129 | 6/28/2026 |
| 1.3.34 | 125 | 6/28/2026 |
| 1.3.33 | 180 | 6/15/2026 |
| 1.3.32 | 144 | 6/12/2026 |
| 1.3.31 | 148 | 6/9/2026 |
| 1.3.30 | 146 | 6/8/2026 |
| 1.3.29 | 150 | 6/5/2026 |
| 1.3.28 | 167 | 6/3/2026 |
| 1.3.27 | 349 | 5/25/2026 |
## v1.3.46 (patch)
Changes since v1.3.45:
- chore: store icon.png in LFS as .gitattributes declares ([@matt-edmondson](https://github.com/matt-edmondson))
- docs: scope build badge to the default branch ([@matt-edmondson](https://github.com/matt-edmondson))