I am currently using a mutex like so (which in turn is a fork of this SO answer):
bool onlyInstance;
using (Mutex mutex = new Mutex(true, "Global\\mutexname", out onlyInstance))
{
try
{
if (onlyInstance)
{
// single instance code
}
}
finally
{
mutex.ReleaseMutex();
}
}
If I'm not wrong, using
uses a try-finally
internally, so is the mutex.ReleaseMutex()
inside the finally redundant since the using would dispose off the mutex anyway? (Assuming a mutex dispose also releases it)