I am creating and using mutex in a windows service
using(var m = new Mutex(false,"mymutex")
{
m.WaitOne();
//to my things for a long time
m.ReleaseMutex();
}
On another program running with Administrator rights I do
Mutex.OpenExisting("mymutex")
and it throws mutex does not exist. I can see in the Resource manager that windows service has reference to the mutex.
What is wrong?
Operating system objects like Mutex have session scope. Your service runs in session 0 so its mutex is not visible to processes that run on the desktop session. The workaround is simple, prefix
Global\to the mutex name.