From aae69ab125a90493508564d8ae8acea1ea23b3d7 Mon Sep 17 00:00:00 2001 From: seraphima Date: Fri, 28 Jun 2024 15:41:26 +0200 Subject: [PATCH] mutex fix --- src/modules/Projects/ProjectsEditor/App.xaml.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/Projects/ProjectsEditor/App.xaml.cs b/src/modules/Projects/ProjectsEditor/App.xaml.cs index e454b4f8be..9188150718 100644 --- a/src/modules/Projects/ProjectsEditor/App.xaml.cs +++ b/src/modules/Projects/ProjectsEditor/App.xaml.cs @@ -17,7 +17,7 @@ namespace ProjectsEditor /// public partial class App : Application, IDisposable { - private static Mutex mutex; + private static Mutex _instanceMutex; public static ProjectsEditorIO ProjectsEditorIO { get; private set; } @@ -41,10 +41,11 @@ namespace ProjectsEditor const string appName = "Local\\PowerToys_Projects_Editor_InstanceMutex"; bool createdNew; - mutex = new Mutex(true, appName, out createdNew); + _instanceMutex = new Mutex(true, appName, out createdNew); if (!createdNew) { Logger.LogWarning("Another instance of Projects Editor is already running. Exiting this instance."); + _instanceMutex = null; Shutdown(0); return; } @@ -90,7 +91,11 @@ namespace ProjectsEditor private void OnExit(object sender, ExitEventArgs e) { - mutex?.ReleaseMutex(); + if (_instanceMutex != null) + { + _instanceMutex.ReleaseMutex(); + } + Dispose(); } @@ -106,6 +111,7 @@ namespace ProjectsEditor if (disposing) { _themeManager?.Dispose(); + _instanceMutex?.Dispose(); } _isDisposed = true;