Skip to content

Commit f5533c2

Browse files
committed
fix: Prevent crash loop on AbandonedMutexException
Closes #413
1 parent 77d7d9d commit f5533c2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

CompactGUI/Application.xaml.vb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@ Class Application
1313

1414
SettingsHandler.InitialiseSettings()
1515

16-
17-
If Not SettingsHandler.AppSettings.AllowMultiInstance AndAlso Not mutex.WaitOne(0, False) Then
16+
Dim acquiredMutex As Boolean
17+
18+
Try
19+
acquiredMutex = mutex.WaitOne(0, False)
20+
Catch ex As AbandonedMutexException
21+
' This means the mutex was acquired successfully,
22+
' but its last owner exited abruptly, without releasing it.
23+
' acquiredMutex should still be True here, but further error checking
24+
' on shared program state could be added here as well.
25+
acquiredMutex = True
26+
End Try
27+
28+
If Not SettingsHandler.AppSettings.AllowMultiInstance AndAlso Not acquiredMutex Then
1829

1930
If e.Args.Length <> 0 AndAlso e.Args(0) = "-tray" Then
2031
MessageBox.Show("An instance of CompactGUI is already running")

0 commit comments

Comments
 (0)