I am trying to prevent multiple copies of an application starting in C# on Windows 8.
bool isMutexNotExist;
var mutex = new Mutex(true, "name", out isMutexNotExist);
if (!isMutexNotExist)
{
SystemSounds.Beep.Play();
Application.Current.Shutdown();
}
mutex.WaitOne();
GC.KeepAlive(mutex);
This code works fine on Windows 7 (Dell Laptop) in Debug and Release mode (Visual Studio 2013) with .Net 4.5 but on Win 8 (Microsoft Surface 3) it lets another copy start. I couldn't find any reference to the Mutex's working different on Win7 & Win8 so i'm not really sure what is going on. The code didn't work on Windows 7 in release mode without the mutex.WaitOne()
.