[DllImport("Kernel32.dll", SetLastError=true)]
static extern IntPtr OpenEvent(uint dwDesiredAccess, bool bInheritHandle, string lpName);
None.
None.
Tip 1: Use OpenEvent to open named event and attach it to AutoResetEvent class:
AutoResetEvent are= new AutoResetEvent(false);
are.Close();
GC.ReRegisterForFinalize(are);
are.Handle= handle; // handle from OpenEvent
// taken from header files
const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000;
const uint SYNCHRONIZE = 0x00100000;
const uint EVENT_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3);
const uint EVENT_MODIFY_STATE = 0x0002 ;
const long ERROR_FILE_NOT_FOUND = 2L;
// open event with error handling
IntPtr handle= OpenEvent(EVENT_ALL_ACCESS | EVENT_MODIFY_STATE, false, name);
int le= Marshal.GetLastWin32Error();
if ((handle==IntPtr.Zero) && (le!=0) && (le!=ERROR_FILE_NOT_FOUND))
throw new ApplicationException(string.Format("Error in pinvoked CreateEvent: {0}", le));
CreateEvent also opens an existing (named) event...