ktsu.SingleAppInstance 1.0.0-pre.4

Prefix Reserved
This is a prerelease version of ktsu.SingleAppInstance.
dotnet add package ktsu.SingleAppInstance --version 1.0.0-pre.4                
NuGet\Install-Package ktsu.SingleAppInstance -Version 1.0.0-pre.4                
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="ktsu.SingleAppInstance" Version="1.0.0-pre.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ktsu.SingleAppInstance --version 1.0.0-pre.4                
#r "nuget: ktsu.SingleAppInstance, 1.0.0-pre.4"                
#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.
// Install ktsu.SingleAppInstance as a Cake Addin
#addin nuget:?package=ktsu.SingleAppInstance&version=1.0.0-pre.4&prerelease

// Install ktsu.SingleAppInstance as a Cake Tool
#tool nuget:?package=ktsu.SingleAppInstance&version=1.0.0-pre.4&prerelease                

ktsu.SingleAppInstance

Overview

The SingleAppInstance class provides a mechanism to ensure that only one instance of an application is running at a time. This is useful for applications that should not have multiple instances running simultaneously, such as desktop applications or services.

Features

  • Single Instance Enforcement: Ensures that only one instance of the application is running.
  • PID File Management: Uses a PID file to track the running instance.
  • Race Condition Handling: Handles potential race conditions when starting multiple instances simultaneously.

Installation

To install the ktsu.SingleAppInstance package, run the following command in a console:

dotnet add package ktsu.SingleAppInstance

Getting Started

To get started with ktsu.SingleAppInstance, follow these steps:

  1. Install the package using the command above.
  2. Add the necessary using directive to your code.
  3. Call the ExitIfAlreadyRunning method at the start of your application.

Usage

To use the SingleAppInstance class, call the ExitIfAlreadyRunning method at the start of your application. This method will check if another instance is already running and exit the current instance if so.

using ktsu.SingleAppInstance;

class Program
{
    static void Main(string[] args)
    {
        SingleAppInstance.ExitIfAlreadyRunning();

    // Your application code here
    }
}

Or if you prefer to explicitly handle the case where another instance is already running, you can call the ShouldLaunch() method to check if another instance is running.

using ktsu.SingleAppInstance;

class Program
{
    static void Main(string[] args)
    {
        if (SingleAppInstance.ShouldLaunch())
        {
            // Your application code here
        }
        else
        {
            // Handle the case where another instance is already running
            Console.WriteLine("Another instance is already running.");
            Environment.Exit(1);
        }
    }
}

Methods

ExitIfAlreadyRunning

Exits the application if another instance is already running.

ShouldLaunch

Determines whether the application should launch.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.0-pre.4 27 1/18/2025
1.0.0-pre.3 32 1/16/2025
1.0.0-pre.2 5 1/14/2025
1.0.0-pre.1 36 1/13/2025
0.0.1-pre.1 29 1/13/2025

## v1.0.0-pre.1 (major)

Changes since v0.0.1-pre.1:

- Remove ktsu.ScopedAction package from project ([@matt-edmondson](https://github.com/matt-edmondson))

## v0.0.1-pre.1 (patch)

Changes since 0.0.0.0:

- Initial commit ([@matt-edmondson](https://github.com/matt-edmondson))
- Remove ktsu.ScopedAction package from project ([@matt-edmondson](https://github.com/matt-edmondson))