title: Access denied on WaitForSingleObject on an event created from managed code
body: <p>How do I create a named event object in C# so that I can wait on it in separate C++ process?</p>
  
  <p>My simplified C# code of process A:</p>
  
  <pre><code>EventWaitHandle evt = new EventWaitHandle(false, EventResetMode.AutoReset, "eventName");
  EventWaitHandle.SignalAndWait(evt , &lt;other event&gt;);
  </code></pre>
  
  <p>And simplified C++ code of process B:</p>
  
  <pre><code>HANDLE hEvt = OpenEvent(
      EVENT_MODIFY_STATE | SYNCHRONIZE,  // access
      FALSE,               // do not inherit handle
      TEXT("eventName")
  );
  
  if (hEvt == NULL)
  {
      printf("CreateEvent failed (%d)\n", GetLastError());
      //error out
  }
  
  DWORD dwWaitResult = WaitForSingleObject(hEvt, INFINITE); 
  switch (dwWaitResult)
  {
      case WAIT_OBJECT_0:
          //Signalled  - all good
          break;
  
      // An error occurred
      default:
          printf("Wait error (%d)\n", GetLastError());
          //error out
  }
  </code></pre>
  
  <p>When I run (or debug) this code, the event is created (C#) and opened (C++) just fine. However I get error 5 (Access Denied) during WaitForSingleObject.
  Adding 'Global\' prefix does not help (nor does adding EventWaitHandleSecurity argument in C# code that allows full control to all build in users).</p>
  
  <p>What I am doing wrong? Is this supposed to work at all?</p>
  
  <p><strong>Edit</strong> Fixed the C++ by adding SYNCHRONIZE desired access. Credit for pointing this out goes to Hans Passant - <a href="https://stackoverflow.com/questions/43791666/access-denied-on-waitforsingleobject-on-an-event-created-from-managed-code#comment74624457_43791666">Access denied on WaitForSingleObject on an event created from managed code</a></p>