我需要做一些跨过程的同步。
Process B should do some actions only when Process A is running. I tried using Mutex and EventWaitHandles like this :
进程A的主要部分:
EventWaitHandle eventWaitHandle = new EventWaitHandle(true, EventResetMode.ManualReset, "SOMEGUID");
进程B:
private static bool IsProcessARunning(string mutexStr)
{
try
{
EventWaitHandle.OpenExisting(mutexStr);
return true;
}
catch (WaitHandleCannotBeOpenedException e)
{
return false;
}
}
But after process A starts once the IsProcessARunning method will always return true even if process A is closed. Any idea what am I doing wrong here ?