Esempio n. 1
0
        private static RegisteredWaitHandle RegisterWaitForSingleObject(  // throws RegisterWaitException
            WaitHandle waitObject,
            WaitOrTimerCallback callBack,
            Object state,
            uint millisecondsTimeOutInterval,
            bool executeOnlyOnce,                                  // NOTE: we do not allow other options that allow the callback to be queued as an APC
            ref StackCrawlMark stackMark,
            bool compressStack
            )
        {
            if (RemotingServices.IsTransparentProxy(waitObject))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WaitOnTransparentProxy"));
            }
            RegisteredWaitHandle registeredWaitHandle = new RegisteredWaitHandle();
            IntPtr nativeRegisteredWaitHandle         = RegisterWaitForSingleObjectNative(waitObject,
                                                                                          callBack,
                                                                                          state,
                                                                                          millisecondsTimeOutInterval,
                                                                                          executeOnlyOnce,
                                                                                          registeredWaitHandle,
                                                                                          ref stackMark,
                                                                                          compressStack);

            registeredWaitHandle.SetHandle(nativeRegisteredWaitHandle);
            return(registeredWaitHandle);
        }
Esempio n. 2
0
        private static RegisteredWaitHandle RegisterWaitForSingleObject(  // throws RegisterWaitException
            WaitHandle waitObject,
            WaitOrTimerCallback callBack,
            object?state,
            uint millisecondsTimeOutInterval,
            bool executeOnlyOnce,    // NOTE: we do not allow other options that allow the callback to be queued as an APC
            bool compressStack
            )
        {
            RegisteredWaitHandle registeredWaitHandle = new RegisteredWaitHandle();

            if (callBack != null)
            {
                _ThreadPoolWaitOrTimerCallback callBackHelper = new _ThreadPoolWaitOrTimerCallback(callBack, state, compressStack);
                state = (object)callBackHelper;
                // call SetWaitObject before native call so that waitObject won't be closed before threadpoolmgr registration
                // this could occur if callback were to fire before SetWaitObject does its addref
                registeredWaitHandle.SetWaitObject(waitObject);
                IntPtr nativeRegisteredWaitHandle = RegisterWaitForSingleObjectNative(waitObject,
                                                                                      state,
                                                                                      millisecondsTimeOutInterval,
                                                                                      executeOnlyOnce,
                                                                                      registeredWaitHandle);
                registeredWaitHandle.SetHandle(nativeRegisteredWaitHandle);
            }
            else
            {
                throw new ArgumentNullException(nameof(WaitOrTimerCallback));
            }
            return(registeredWaitHandle);
        }
Esempio n. 3
0
        private static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce, ref StackCrawlMark stackMark, bool compressStack)
        {
            if (RemotingServices.IsTransparentProxy((object)waitObject))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WaitOnTransparentProxy"));
            }
            RegisteredWaitHandle registeredWaitHandle = new RegisteredWaitHandle();

            if (callBack == null)
            {
                throw new ArgumentNullException("WaitOrTimerCallback");
            }
            state = (object)new _ThreadPoolWaitOrTimerCallback(callBack, state, compressStack, ref stackMark);
            registeredWaitHandle.SetWaitObject(waitObject);
            IntPtr handle = ThreadPool.RegisterWaitForSingleObjectNative(waitObject, state, millisecondsTimeOutInterval, executeOnlyOnce, registeredWaitHandle, ref stackMark, compressStack);

            registeredWaitHandle.SetHandle(handle);
            return(registeredWaitHandle);
        }
Esempio n. 4
0
        private static RegisteredWaitHandle RegisterWaitForSingleObject(  // throws RegisterWaitException
            WaitHandle waitObject,
            WaitOrTimerCallback callBack,
            Object state,
            uint millisecondsTimeOutInterval,
            bool executeOnlyOnce,                  // NOTE: we do not allow other options that allow the callback to be queued as an APC
            ref StackCrawlMark stackMark,
            bool compressStack
            )
        {
            if (RemotingServices.IsTransparentProxy(waitObject))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WaitOnTransparentProxy"));
            }
            RegisteredWaitHandle registeredWaitHandle = new RegisteredWaitHandle();

            if (callBack != null)
            {
                _ThreadPoolWaitOrTimerCallback callBackHelper = new _ThreadPoolWaitOrTimerCallback(callBack, state, compressStack, ref stackMark);
                state = (Object)callBackHelper;
                // call SetWaitObject before native call so that waitObject won't be closed before threadpoolmgr registration
                // this could occur if callback were to fire before SetWaitObject does its addref
                registeredWaitHandle.SetWaitObject(waitObject);
                IntPtr nativeRegisteredWaitHandle = RegisterWaitForSingleObjectNative(waitObject,
                                                                                      state,
                                                                                      millisecondsTimeOutInterval,
                                                                                      executeOnlyOnce,
                                                                                      registeredWaitHandle,
                                                                                      ref stackMark,
                                                                                      compressStack);
                registeredWaitHandle.SetHandle(nativeRegisteredWaitHandle);
            }
            else
            {
                throw new ArgumentNullException("WaitOrTimerCallback");
            }
            return(registeredWaitHandle);
        }
        private static RegisteredWaitHandle RegisterWaitForSingleObject(  // throws RegisterWaitException
             WaitHandle             waitObject,
             WaitOrTimerCallback    callBack,
             Object                 state,
             uint               millisecondsTimeOutInterval,
             bool               executeOnlyOnce,   // NOTE: we do not allow other options that allow the callback to be queued as an APC
             ref StackCrawlMark stackMark,
             bool               compressStack
             )
        {
            if (RemotingServices.IsTransparentProxy(waitObject))
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WaitOnTransparentProxy"));
            RegisteredWaitHandle registeredWaitHandle = new RegisteredWaitHandle();

            if (callBack != null)
            {
                _ThreadPoolWaitOrTimerCallback callBackHelper = new _ThreadPoolWaitOrTimerCallback(callBack, state, compressStack, ref stackMark);
                state = (Object)callBackHelper;
                // call SetWaitObject before native call so that waitObject won't be closed before threadpoolmgr registration
                // this could occur if callback were to fire before SetWaitObject does its addref
                registeredWaitHandle.SetWaitObject(waitObject);
                IntPtr nativeRegisteredWaitHandle = RegisterWaitForSingleObjectNative(waitObject,
                                                                               state, 
                                                                               millisecondsTimeOutInterval,
                                                                               executeOnlyOnce,
                                                                               registeredWaitHandle,
                                                                               ref stackMark,
                                                                               compressStack);
                registeredWaitHandle.SetHandle(nativeRegisteredWaitHandle);
            }
            else
            {
                throw new ArgumentNullException("WaitOrTimerCallback");
            }
            return registeredWaitHandle;
        }
 private static RegisteredWaitHandle RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce, ref StackCrawlMark stackMark, bool compressStack)
 {
     if (RemotingServices.IsTransparentProxy(waitObject))
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WaitOnTransparentProxy"));
     }
     RegisteredWaitHandle registeredWaitHandle = new RegisteredWaitHandle();
     if (callBack == null)
     {
         throw new ArgumentNullException("WaitOrTimerCallback");
     }
     _ThreadPoolWaitOrTimerCallback callback = new _ThreadPoolWaitOrTimerCallback(callBack, state, compressStack, ref stackMark);
     state = callback;
     registeredWaitHandle.SetWaitObject(waitObject);
     IntPtr handle = RegisterWaitForSingleObjectNative(waitObject, state, millisecondsTimeOutInterval, executeOnlyOnce, registeredWaitHandle, ref stackMark, compressStack);
     registeredWaitHandle.SetHandle(handle);
     return registeredWaitHandle;
 }
Esempio n. 7
0
    	private static RegisteredWaitHandle RegisterWaitForSingleObject(  // throws RegisterWaitException
    	     WaitHandle 			waitObject,
             WaitOrTimerCallback	callBack,
             Object					state,
    		 uint				millisecondsTimeOutInterval,
             bool				executeOnlyOnce,   // NOTE: we do not allow other options that allow the callback to be queued as an APC
             ref StackCrawlMark stackMark,
             bool               compressStack
    		 )
        {
            if (RemotingServices.IsTransparentProxy(waitObject))
				throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WaitOnTransparentProxy"));
            RegisteredWaitHandle registeredWaitHandle = new RegisteredWaitHandle();
    		IntPtr nativeRegisteredWaitHandle = RegisterWaitForSingleObjectNative(waitObject,
			                                                                   callBack,
																			   state, 
																			   millisecondsTimeOutInterval,
																			   executeOnlyOnce,
																			   registeredWaitHandle,
                                                                               ref stackMark,
                                                                               compressStack);
            registeredWaitHandle.SetHandle(nativeRegisteredWaitHandle);
    		return registeredWaitHandle;
    	}