Ejemplo n.º 1
0
        private static RegisteredWaitHandle RegisterWaitForSingleObject(
            WaitHandle?waitObject,
            WaitOrTimerCallback?callBack,
            object?state,
            uint millisecondsTimeOutInterval,
            bool executeOnlyOnce,
            bool flowExecutionContext
            )
        {
            if (waitObject == null)
            {
                throw new ArgumentNullException(nameof(waitObject));
            }

            if (callBack == null)
            {
                throw new ArgumentNullException(nameof(callBack));
            }

            RegisteredWaitHandle registeredWaitHandle = new RegisteredWaitHandle(
                waitObject,
                new _ThreadPoolWaitOrTimerCallback(callBack, state, flowExecutionContext),
                (int)millisecondsTimeOutInterval,
                !executeOnlyOnce
                );

            registeredWaitHandle.OnBeforeRegister();

            if (UsePortableThreadPool)
            {
                PortableThreadPool.ThreadPoolInstance.RegisterWaitHandle(registeredWaitHandle);
            }
            else
            {
                IntPtr nativeRegisteredWaitHandle = RegisterWaitForSingleObjectNative(
                    waitObject,
                    registeredWaitHandle.Callback,
                    (uint)registeredWaitHandle.TimeoutDurationMs,
                    !registeredWaitHandle.Repeating,
                    registeredWaitHandle
                    );
                registeredWaitHandle.SetNativeRegisteredWaitHandle(nativeRegisteredWaitHandle);
            }

            return(registeredWaitHandle);
        }
Ejemplo n.º 2
0
        private static void RegisterWaitForSingleObjectCore(WaitHandle waitObject, RegisteredWaitHandle registeredWaitHandle)
        {
            registeredWaitHandle.OnBeforeRegister();

            if (UsePortableThreadPool)
            {
                PortableThreadPool.ThreadPoolInstance.RegisterWaitHandle(registeredWaitHandle);
                return;
            }

            IntPtr nativeRegisteredWaitHandle =
                RegisterWaitForSingleObjectNative(
                    waitObject,
                    registeredWaitHandle.Callback,
                    (uint)registeredWaitHandle.TimeoutDurationMs,
                    !registeredWaitHandle.Repeating,
                    registeredWaitHandle);

            registeredWaitHandle.SetNativeRegisteredWaitHandle(nativeRegisteredWaitHandle);
        }