I have two processes, one created using C# and the other created using native C++.
I want to synchronize the two processes so that the unmanaged one will be blocked until the managed one is up and running.
In the managed process I have the following code:
// signal the unmanaged process that I am up and running
EventWaitHandle eventWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, "MyEventName");
eventWaitHandle.Set();
In the unmanaged process I have the corresponding code to wait for the event
HANDLE hWaitEvent = CreateEventW(NULL, TRUE, FALSE, "MyEventName");
if (hWaitEvent)
{
// wait for managed process to signal that it is up and running
WaitForSingleObject(hWaitEvent, 5000);
}
As far as I can tell, after the event is set in the first process. The WaitForSingleObject in the other process fail to detect that and always waits until times-out.
Is there anything that I missed? Thanks.
Yes, that does not work, you are creating an event on both ends. One of them has to create it, the other has to open it. OpenEvent() in the C++ code or EventWaitHandle.OpenExisting() in the C# code. Whatever code starts first must create the event.