Thread synchronization to win32/x64 application via EventWaitHandle fails RRS feed

  • Question

  • Hello,

    I want to synchronize a 32Bit .NET application with a native 64 bit application. The native app writes image data into a memory mapped file and the .NET app is supposed to refresh a display window when new data is available. This works via wrapping the native win32 event handle in a C++/CLI dll but I now want to get rid of unmanaged code. As I read that the .Net EventWaitHandle is a wrapper around the win32 event handle I tried to create an autoreset event - which unfortunately is not triggered by the native event.

    The Win32 Code Snippet:

    void* m_hWaitEvent = CreateEventA(NULL, FALSE, FALSE, i_strWinEventName); // where strWinEventName is "LsfmMmfEvent"


    The C# code snippet:

    EventWaitHandle _WaitHandle = EventWaitHandle.OpenExisting("LsfmMmfEvent");

    If the native app runs, EventWaitHandle.OpenExisting returns a valid EventWaitHandle. Otherwise it throws a WaitHandleCannotBeOpenedException. So I guess I am opening the right handle. I am still running the old implementation in parallel and I see that the win32 event handle is triggered continuously. But the .NET thread waiting with _WaitHandle.WaitOne() is stuck forever.  


    Thx in advance for your help

    Tuesday, July 12, 2011 9:24 AM


  • That is because you run the other program in parallel and because the event is auto-reset.  Auto-reset means it will be set to FALSE (or not set) after unblocking a thread and before any other thread is unblocked.  You need a manual reset event if you want to run two clients for the same server.
    • Proposed as answer by Paul Zhou Thursday, July 14, 2011 2:57 AM
    • Marked as answer by Neutronensturm Thursday, July 14, 2011 2:00 PM
    Tuesday, July 12, 2011 2:13 PM