I am trying to set up a mutex to prevent my application launcher executable from starting several identical processes. I have seen several people using similar code with Application.Run() instead of Process.Start(), where one blocks while the other does not. My code seemingly does what it should, but I do not understand why. The application launcher exits shortly after the code below, so would the mutex not be disposed?
// Prevent multiple application instances by checking our global mutex.
using (var mutex = new Mutex(false, @"Global\" + ApplicationGuid))
{
if (!mutex.WaitOne(0, false))
{
MessageBox.Show("An instance of this application is already running.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Start application.
Process.Start(applicationPath);
}