mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-18 10:25:00 +03:00
fix: keep the Linux single-instance mutex alive (#10629)
Store the named mutex in a static field. Discarding it lets the runtime release/finalize it, so a second launch no longer sees the first instance and a new process starts.
This commit is contained in:
@@ -6,6 +6,7 @@ namespace v2rayN.Desktop;
|
|||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
public static EventWaitHandle ProgramStarted;
|
public static EventWaitHandle ProgramStarted;
|
||||||
|
private static Mutex? _instanceMutex;
|
||||||
|
|
||||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||||
@@ -38,7 +39,9 @@ internal class Program
|
|||||||
}
|
}
|
||||||
else
|
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)
|
if (!bOnlyOneInstance)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user