I was playing with Mutex to understand if it can be used to know whether Microsoft Word is currently running in a computer with logged in user session. I tried below examples but none of them worked.
Ex1:
using (Mutex mutex = new Mutex(false, "WINWORD.exe"))
{
if (mutex.WaitOne(0, false))
{
Console.WriteLine("Not running"); //Always printing
}
else
{
Console.WriteLine("Already running");
}
}
Ex2:
bool createdNew;
Mutex m = new Mutex(false, "WINWORD.exe", out createdNew);
if (createdNew)
{
Console.WriteLine("Not running"); //Always printing
}
else
{
Console.WriteLine("Already running");
}
In both the example, it's printing "Not running", although I can see Word in running in my computer. Is it a limitation of Mutex? Or am I missing something here?