diff --git a/v2rayN/v2rayN.Desktop/Program.cs b/v2rayN/v2rayN.Desktop/Program.cs index 62d8d721..784ae6ce 100644 --- a/v2rayN/v2rayN.Desktop/Program.cs +++ b/v2rayN/v2rayN.Desktop/Program.cs @@ -6,6 +6,7 @@ namespace v2rayN.Desktop; internal class Program { public static EventWaitHandle ProgramStarted; + private static Mutex? _instanceMutex; // Initialization code. Don't use any Avalonia, third-party APIs or any // SynchronizationContext-reliant code before AppMain is called: things aren't initialized @@ -38,7 +39,9 @@ internal class Program } else { - _ = new Mutex(true, "v2rayN", out var bOnlyOneInstance); + // Keep the named mutex alive for the process lifetime. Discarding the handle lets + // the runtime finalize it, so the next launch sees no running instance. + _instanceMutex = new Mutex(true, "v2rayN", out var bOnlyOneInstance); if (!bOnlyOneInstance) { return false;