Skip to content

fix: enforce single instance with mutex + named pipe#11

Merged
chrisuthe merged 2 commits intomasterfrom
fix/single-instance-enforcement
Mar 4, 2026
Merged

fix: enforce single instance with mutex + named pipe#11
chrisuthe merged 2 commits intomasterfrom
fix/single-instance-enforcement

Conversation

@chrisuthe
Copy link
Owner

Summary

Prevents multiple instances of the Sendspin Windows client from running simultaneously. When a second instance is launched while one is already in the system tray, it signals the existing instance to show its window and exits silently.

  • New: SingleInstanceGuard.cs — Uses a named Mutex for detection and a NamedPipeServerStream for cross-process signaling
  • Modified: App.xaml.cs — Guard check at the top of OnStartup before any DI, logging, or window creation

How it works

  1. First instance creates a named mutex and starts listening on a named pipe
  2. Second instance detects the mutex already exists, connects to the pipe (signals "show window"), then exits
  3. First instance receives the pipe connection and brings its window to the foreground

Edge cases handled

  • Crash recovery: Mutex is a kernel object — OS releases it when the process dies
  • Race condition: If first instance exits between mutex check and pipe connect, pipe fails silently and second instance starts normally
  • Rapid launches: Pipe server loops to handle successive connections

Test plan

  • Launch app, verify it starts normally with tray icon
  • Launch app again — existing window comes to foreground, no second tray icon
  • Close window to tray, launch again — window reappears
  • Exit app, launch fresh — starts normally as first instance

🤖 Generated with Claude Code

chrisuthe and others added 2 commits March 3, 2026 23:23
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Second launch signals the existing instance to show its window via a
named pipe, then exits silently. Prevents duplicate tray icons, audio
pipelines, and server discovery services.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chrisuthe chrisuthe merged commit 7031a14 into master Mar 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant