I got an interesting problem (C#/WPF application). I am using this code to prevent second instance of my application from running.
Mutex _mutex; string mutexName = "Global\\{SOME_GUID}"; try { _mutex = new Mutex(false, mutexName); } catch (Exception) { //Possible second instance, do something here. } if (_mutex.WaitOne(0, false)) { base.OnStartup(e); } else { //Do something here to close the second instance } If I put the code directly in the main exe under OnStartup method it works. However if I wrap the same code and put it in a separate assembly/dll and call the function from OnStartup method it doesn't detect second instance.
Any suggestions?