Beispiel #1
0
		public static bool ResetEvent (SafeWaitHandle handle)
		{
			bool release = false;
			try {
				handle.DangerousAddRef (ref release);
				return ResetEvent_internal (handle.DangerousGetHandle ());
			} finally {
				if (release)
					handle.DangerousRelease ();
			}
		}
Beispiel #2
0
 internal static int MsgWaitForMultipleObjects(SafeWaitHandle handle, bool waitAll, int milliseconds, int wakeMask)
 {
     int terminationEvent, lastWin32Error;
     if (handle == null)
     {
         terminationEvent = UnsafeNativeMethods.MsgWaitForMultipleObjects(0, null, waitAll, milliseconds, wakeMask);
         lastWin32Error = Marshal.GetLastWin32Error();
     }
     else
     {
         RuntimeHelpers.PrepareConstrainedRegions();
         bool fRelease = false;
         try
         {
             handle.DangerousAddRef(ref fRelease);
             IntPtr[] handles = { handle.DangerousGetHandle() };
             terminationEvent = UnsafeNativeMethods.MsgWaitForMultipleObjects(1, handles, waitAll, milliseconds, wakeMask);
             lastWin32Error = Marshal.GetLastWin32Error();
         }
         finally
         {
             if (fRelease)
             {
                 handle.DangerousRelease();
             }
         }
     }
     if (terminationEvent == NativeMethods.WAIT_FAILED)
     {
         ThrowWin32ExceptionsIfError(lastWin32Error);
     }
     return terminationEvent;
 }
Beispiel #3
0
        internal static int WaitOneNative(SafeWaitHandle waitableSafeHandle, long millisecondsTimeout)
        {
            Debug.Assert(millisecondsTimeout >= -1 && millisecondsTimeout <= int.MaxValue);

            waitableSafeHandle.DangerousAddRef();
            try
            {
                return LowLevelThread.WaitForSingleObject(waitableSafeHandle.DangerousGetHandle(), (int)millisecondsTimeout);
            }
            finally
            {
                waitableSafeHandle.DangerousRelease();
            }
        }
Beispiel #4
0
		static int SignalAndWaitOne (SafeWaitHandle waitHandleToSignal,SafeWaitHandle waitHandleToWaitOn, int millisecondsTimeout, bool hasThreadAffinity,  bool exitContext)
		{
			bool releaseHandleToSignal = false, releaseHandleToWaitOn = false;
			try {
				waitHandleToSignal.DangerousAddRef (ref releaseHandleToSignal);
				waitHandleToWaitOn.DangerousAddRef (ref releaseHandleToWaitOn);

				return SignalAndWait_Internal (waitHandleToSignal.DangerousGetHandle (), waitHandleToWaitOn.DangerousGetHandle (), millisecondsTimeout);
			} finally {
				if (releaseHandleToSignal)
					waitHandleToSignal.DangerousRelease ();
				if (releaseHandleToWaitOn)
					waitHandleToWaitOn.DangerousRelease ();
			}
		}