Open pertsov opened 2 years ago
// Make sure that appMutex has the lifetime of the code to guard -- // you must keep it from being collected (and the finalizer called, which // will release the mutex, which is not good here!). // You can also poke the mutex later. Mutex appMutex;
// In some startup/initialization code bool createdNew; appMutex = new Mutex(true, "mutexname", out createdNew); if (!createdNew) { // The mutex already existed - exit application. // Windows will release the resources for the process and the // mutex will go away when no process has it open. // Processes are much more cleaned-up after than threads :) } else { // win \o/ }
2