{"id":26800529,"url":"https://github.com/ktsu-dev/singleappinstance","last_synced_at":"2026-07-04T01:04:31.665Z","repository":{"id":272219237,"uuid":"915867309","full_name":"ktsu-dev/SingleAppInstance","owner":"ktsu-dev","description":"A lightweight .NET library that ensures only one instance of an application is running at a time.","archived":false,"fork":false,"pushed_at":"2026-06-03T23:40:30.000Z","size":490,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-04T02:12:35.075Z","etag":null,"topics":["application-lifecycle","c","cross-platform","csharp","desktop-application","dotnet","instance-management","library","lightweight","mit-license","mutex","net","pid","pid-file","process","race-condition","single-app-instance","single-instance"],"latest_commit_sha":null,"homepage":"https://ktsu.dev","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ktsu-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":"COPYRIGHT.md","agents":null,"dco":null,"cla":null}},"created_at":"2025-01-13T01:51:38.000Z","updated_at":"2026-06-03T23:37:27.000Z","dependencies_parsed_at":"2026-05-01T12:01:40.795Z","dependency_job_id":null,"html_url":"https://github.com/ktsu-dev/SingleAppInstance","commit_stats":null,"previous_names":["ktsu-dev/singleappinstance"],"tags_count":117,"template":false,"template_full_name":null,"purl":"pkg:github/ktsu-dev/SingleAppInstance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSingleAppInstance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSingleAppInstance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSingleAppInstance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSingleAppInstance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktsu-dev","download_url":"https://codeload.github.com/ktsu-dev/SingleAppInstance/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSingleAppInstance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34086681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["application-lifecycle","c","cross-platform","csharp","desktop-application","dotnet","instance-management","library","lightweight","mit-license","mutex","net","pid","pid-file","process","race-condition","single-app-instance","single-instance"],"created_at":"2025-03-29T20:17:45.435Z","updated_at":"2026-06-09T01:05:37.017Z","avatar_url":"https://github.com/ktsu-dev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ktsu.SingleAppInstance\n\n\u003e A .NET library that ensures only one instance of your application is running at a time.\n\n[![License](https://img.shields.io/github/license/ktsu-dev/SingleAppInstance.svg?label=License\u0026logo=nuget)](LICENSE.md)\n[![NuGet Version](https://img.shields.io/nuget/v/ktsu.SingleAppInstance?label=Stable\u0026logo=nuget)](https://nuget.org/packages/ktsu.SingleAppInstance)\n[![NuGet Version](https://img.shields.io/nuget/vpre/ktsu.SingleAppInstance?label=Latest\u0026logo=nuget)](https://nuget.org/packages/ktsu.SingleAppInstance)\n[![NuGet Downloads](https://img.shields.io/nuget/dt/ktsu.SingleAppInstance?label=Downloads\u0026logo=nuget)](https://nuget.org/packages/ktsu.SingleAppInstance)\n[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/ktsu-dev/SingleAppInstance?label=Commits\u0026logo=github)](https://github.com/ktsu-dev/SingleAppInstance/commits/main)\n[![GitHub contributors](https://img.shields.io/github/contributors/ktsu-dev/SingleAppInstance?label=Contributors\u0026logo=github)](https://github.com/ktsu-dev/SingleAppInstance/graphs/contributors)\n[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ktsu-dev/SingleAppInstance/dotnet.yml?label=Build\u0026logo=github)](https://github.com/ktsu-dev/SingleAppInstance/actions)\n\n## Introduction\n\n`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.\n\n## Features\n\n- **Single Instance Enforcement**: Prevents multiple copies of your application from running simultaneously\n- **Enhanced Process Identification**: Verifies running instances using multiple attributes (PID, process name, start time, executable path) for accurate detection\n- **Race Condition Handling**: Includes a built-in 1-second delay to safely detect simultaneous startup attempts\n- **PID File Management**: Stores process information as JSON in the application data directory\n- **Backward Compatibility**: Gracefully handles legacy PID files that stored only a plain integer PID\n- **Simple API**: Two methods — `ExitIfAlreadyRunning()` for automatic exit and `ShouldLaunch()` for custom logic\n- **Multi-Target Support**: Works across .NET 10.0 through .NET 5.0, .NET Standard 2.0/2.1\n\n## Installation\n\n### Package Manager Console\n\n```powershell\nInstall-Package ktsu.SingleAppInstance\n```\n\n### .NET CLI\n\n```bash\ndotnet add package ktsu.SingleAppInstance\n```\n\n### Package Reference\n\n```xml\n\u003cPackageReference Include=\"ktsu.SingleAppInstance\" Version=\"x.y.z\" /\u003e\n```\n\n## Usage Examples\n\n### Basic Example\n\nThe simplest way to use SingleAppInstance is to call `ExitIfAlreadyRunning` at the start of your application. If another instance is detected, the process exits automatically:\n\n```csharp\nusing ktsu.SingleAppInstance;\n\nclass Program\n{\n    static void Main(string[] args)\n    {\n        SingleAppInstance.ExitIfAlreadyRunning();\n\n        // Your application code here\n        Console.WriteLine(\"Application is running.\");\n    }\n}\n```\n\n### Custom Launch Logic\n\nIf you prefer to handle the duplicate-instance case yourself, use `ShouldLaunch()` which returns a boolean:\n\n```csharp\nusing ktsu.SingleAppInstance;\n\nclass Program\n{\n    static void Main(string[] args)\n    {\n        if (SingleAppInstance.ShouldLaunch())\n        {\n            // Your application code here\n            Console.WriteLine(\"Application is running.\");\n        }\n        else\n        {\n            Console.WriteLine(\"Another instance is already running.\");\n        }\n    }\n}\n```\n\n### WPF Application Integration\n\n```csharp\nusing System.Windows;\nusing ktsu.SingleAppInstance;\n\nnamespace MyWpfApp\n{\n    public partial class App : Application\n    {\n        protected override void OnStartup(StartupEventArgs e)\n        {\n            base.OnStartup(e);\n\n            if (!SingleAppInstance.ShouldLaunch())\n            {\n                MessageBox.Show(\"Application is already running.\");\n                Shutdown();\n                return;\n            }\n\n            MainWindow = new MainWindow();\n            MainWindow.Show();\n        }\n    }\n}\n```\n\n## API Reference\n\n### `SingleAppInstance`\n\nA static class that provides single-instance enforcement for applications. Uses a PID file stored in the application data directory to track running instances.\n\n#### Methods\n\n| Name | Return Type | Description |\n| --- | --- | --- |\n| `ExitIfAlreadyRunning()` | `void` | Checks if another instance is running and calls `Environment.Exit(0)` if so |\n| `ShouldLaunch()` | `bool` | Writes a PID file, waits 1 second for race condition detection, and returns `true` if safe to proceed |\n\n## Contributing\n\nContributions are welcome! Feel free to open issues or submit pull requests.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fsingleappinstance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktsu-dev%2Fsingleappinstance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fsingleappinstance/lists"}