I create a mutex within the OnStartup
Method of a WPF app. The mutex is not used anywhere else in the program, its only purpose is to prevent certain programs from
I personally wouldn't bother releasing it at all, especially since you handle AbandonedMutexException
.
If a mutex is not used to synchronize threads of the same process there is no need to explicitly release it. When a process terminates OS automatically closes all handles created by the process, such as files, sockets, mutexes, semaphores and event handles .
If you still prefer to release it consider using Application.OnExit()
since it is called from the main thread, just like the Startup()
.