Skip to content

Commit 0bf01be

Browse files
committed
Fix - App crashed while creating new Mutex
1 parent 46be0a3 commit 0bf01be

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

‎Source/NETworkManager/App.xaml.cs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public partial class App : Application
1515
{
1616
// Single instance unique identifier
1717
private const string Guid = "6A3F34B2-161F-4F70-A8BC-A19C40F79CFB";
18-
static Mutex _mutex = new Mutex(true, "{" + Guid + "}");
18+
Mutex _mutex;
1919

2020
private bool _singleInstanceClose = false;
2121

@@ -58,15 +58,13 @@ private void Application_Startup(object sender, StartupEventArgs e)
5858
return;
5959
}
6060

61-
bool applicationIsRunning = !_mutex.WaitOne(TimeSpan.Zero, true);
62-
6361
// Single instance
64-
if (SettingsManager.Current.Window_MultipleInstances || !applicationIsRunning)
62+
_mutex = new Mutex(true, "{" + Guid + "}");
63+
64+
if (SettingsManager.Current.Window_MultipleInstances || _mutex.WaitOne(TimeSpan.Zero, true))
6565
{
6666
StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);
67-
68-
if (!applicationIsRunning)
69-
_mutex.ReleaseMutex();
67+
_mutex.ReleaseMutex();
7068
}
7169
else
7270
{
@@ -91,7 +89,7 @@ private void Application_Exit(object sender, ExitEventArgs e)
9189
{
9290
// Save settings, when the application is normally closed
9391
if (!_singleInstanceClose && !ImportExportManager.ForceRestart && !CommandLineManager.Current.Help)
94-
{
92+
{
9593
if (SettingsManager.Current.SettingsChanged)
9694
SettingsManager.Save();
9795
}

0 commit comments

Comments
 (0)