Attempting to grab the mutex during application startup can throw an AbandonedMutexException, which successfully acquires the mutex, but will crash the program if not handled. When it crashes, it abandons the mutex again, ultimately causing the program to crash repeatedly on every launch until the mutex is cleaned up by some other mechanism.
There are two prerequisites to get into this situation:
Something else causes the mutex to be abandoned the first time (some unrelated crash)
Another process is holding an open handle to the mutex between program launches and prevents it from being cleaned up by the operating system (which would reset its state automatically)
I noticed this because of some other bug that was leaving an instance application in a quasi-shut-down state (no remaining application window, and not holding that mutex, but not fully exiting and releasing handles), which then made all subsequent launches fail until the odd one was terminated via task manager. It's a pretty niche set of circumstances, but should be pretty easy to handle to prevent that sort of crash loop from coming up. Either ignoring the AbandonedMutexException and treating it as a successful acquire (since it still is one) or attempting to clean up the program state by terminating all other CompactGUI instances (since something is broken at that point) might be reasonable approaches.
Attempting to grab the mutex during application startup can throw an
AbandonedMutexException
, which successfully acquires the mutex, but will crash the program if not handled. When it crashes, it abandons the mutex again, ultimately causing the program to crash repeatedly on every launch until the mutex is cleaned up by some other mechanism.There are two prerequisites to get into this situation:
I noticed this because of some other bug that was leaving an instance application in a quasi-shut-down state (no remaining application window, and not holding that mutex, but not fully exiting and releasing handles), which then made all subsequent launches fail until the odd one was terminated via task manager. It's a pretty niche set of circumstances, but should be pretty easy to handle to prevent that sort of crash loop from coming up. Either ignoring the
AbandonedMutexException
and treating it as a successful acquire (since it still is one) or attempting to clean up the program state by terminating all other CompactGUI instances (since something is broken at that point) might be reasonable approaches.