Hi there,
I'm trying to understand the impact of killing a process that owns a
system mutex (used to ensure there is only 1 instance of my program
running)
Here is my code pretty much:
try
{
mutex=new System.Threading.Mutex( true, mutexName, out createdNew)
)
if (!createdNew)
{
Console.Error.WriteLine("Another Instance is already running");
return (int) AppErrorCode.AlreadyRunning;
}
}
catch
{
.... Some code ...
}
if(createdNew)
{
mutex.ReleaseMutex();
}
1st question: Should I always release the mutex or only in the instance
which created it.
2nd question: What happens if my program hangs and needs to be killed
(via the task manager).
The next time the program is run, will createdNew be equal to true or
false (because it is reusing the mutex that was created by the killed
instance)
3rd question: should I use the using( mutex = new Mutex ) instead?
If so, then what happens in the instance that created the mutex? In the
second instance that attempted to access the mutex?
Bonus question: any better suggestion to make sure that only 1 instance
of the process can run at a given moment?
Thank for the help.