Example #1
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);
        }