Amib.Threading.Internal.EventWaitHandleFactory.ReplaceEventHandle C# (CSharp) Method

ReplaceEventHandle() private static method

Replace the event handle
private static ReplaceEventHandle ( WaitHandle waitHandle, bool manualReset, bool initialState ) : void
waitHandle System.Threading.WaitHandle The WaitHandle object which its handle needs to be replaced.
manualReset bool Indicates if the event is a ManualResetEvent (true) or an AutoResetEvent (false)
initialState bool The initial state of the event
return void
        private static void ReplaceEventHandle(WaitHandle waitHandle, bool manualReset, bool initialState)
        {
            // Store the old handle
            IntPtr oldHandle = waitHandle.Handle;

            // Create a new event
            IntPtr newHandle = CreateEvent(IntPtr.Zero, manualReset, initialState, null);

            // Replace the old event with the new event
            waitHandle.Handle = newHandle;

            // Close the old event
            CloseHandle (oldHandle);
        }