protected override void OnStartup(StartupEventArgs e) { if (e.Args.Length > 0) { PathArg = e.Args[0]; } try { mutex = new Mutex(true, "valyreon.subloader", out var isOnlyInstance); if (!isOnlyInstance) { if (!string.IsNullOrWhiteSpace(PathArg)) { InstanceMediator.SendArgumentToRunningInstance(PathArg); } Cleanup(); Environment.Exit(0); } InstanceMediator = new InstanceMediator(); InstanceMediator.StartListening(); } catch { Cleanup(); } base.OnStartup(e); }
private void Cleanup() { InstanceMediator?.StopListening(); mutex?.ReleaseMutex(); mutex?.Dispose(); }