mutex fix

This commit is contained in:
seraphima
2024-06-28 15:41:26 +02:00
parent 8344060e5e
commit aae69ab125

View File

@@ -17,7 +17,7 @@ namespace ProjectsEditor
/// </summary> /// </summary>
public partial class App : Application, IDisposable public partial class App : Application, IDisposable
{ {
private static Mutex mutex; private static Mutex _instanceMutex;
public static ProjectsEditorIO ProjectsEditorIO { get; private set; } public static ProjectsEditorIO ProjectsEditorIO { get; private set; }
@@ -41,10 +41,11 @@ namespace ProjectsEditor
const string appName = "Local\\PowerToys_Projects_Editor_InstanceMutex"; const string appName = "Local\\PowerToys_Projects_Editor_InstanceMutex";
bool createdNew; bool createdNew;
mutex = new Mutex(true, appName, out createdNew); _instanceMutex = new Mutex(true, appName, out createdNew);
if (!createdNew) if (!createdNew)
{ {
Logger.LogWarning("Another instance of Projects Editor is already running. Exiting this instance."); Logger.LogWarning("Another instance of Projects Editor is already running. Exiting this instance.");
_instanceMutex = null;
Shutdown(0); Shutdown(0);
return; return;
} }
@@ -90,7 +91,11 @@ namespace ProjectsEditor
private void OnExit(object sender, ExitEventArgs e) private void OnExit(object sender, ExitEventArgs e)
{ {
mutex?.ReleaseMutex(); if (_instanceMutex != null)
{
_instanceMutex.ReleaseMutex();
}
Dispose(); Dispose();
} }
@@ -106,6 +111,7 @@ namespace ProjectsEditor
if (disposing) if (disposing)
{ {
_themeManager?.Dispose(); _themeManager?.Dispose();
_instanceMutex?.Dispose();
} }
_isDisposed = true; _isDisposed = true;