public static ThreadPoolCallbackWrapper Enter()
 {
     return(new ThreadPoolCallbackWrapper
     {
         _currentThread = RuntimeThread.InitializeThreadPoolThread(),
     });
 }
Esempio n. 2
0
        private static void LongRunningWorkCallback(IntPtr instance, IntPtr context)
        {
            RuntimeThread.InitializeThreadPoolThread();

            GCHandle gcHandle = GCHandle.FromIntPtr(context);
            Action   callback = (Action)gcHandle.Target;

            gcHandle.Free();

            callback();
        }
Esempio n. 3
0
        private static IntPtr ThreadPoolDispatchCallback(IntPtr context)
        {
            RuntimeThread.InitializeThreadPoolThread();

            do
            {
                // Handle pending requests
                ThreadPoolWorkQueue.Dispatch();

                // Wait for new requests to arrive
                s_semaphore.Wait();
            } while (true);
        }
Esempio n. 4
0
        internal static void RegisteredWaitCallback(IntPtr instance, IntPtr context, IntPtr wait, uint waitResult)
        {
            RuntimeThread.InitializeThreadPoolThread();

            GCHandle             handle = (GCHandle)context;
            RegisteredWaitHandle registeredWaitHandle = (RegisteredWaitHandle)handle.Target;

            Debug.Assert((handle == registeredWaitHandle._gcHandle) && (wait == registeredWaitHandle._tpWait));

            bool timedOut = (waitResult == (uint)Interop.Constants.WaitTimeout);

            registeredWaitHandle.PerformCallback(timedOut);
        }
Esempio n. 5
0
        private static unsafe void OnNativeIOCompleted(IntPtr instance, IntPtr context, IntPtr overlappedPtr, uint ioResult, UIntPtr numberOfBytesTransferred, IntPtr ioPtr)
        {
            RuntimeThread.InitializeThreadPoolThread();
            Win32ThreadPoolNativeOverlapped *overlapped = (Win32ThreadPoolNativeOverlapped *)overlappedPtr;

            ThreadPoolBoundHandle boundHandle = overlapped->Data._boundHandle;

            if (boundHandle == null)
            {
                throw new InvalidOperationException(SR.Argument_NativeOverlappedAlreadyFree);
            }

            boundHandle.Release();

            Win32ThreadPoolNativeOverlapped.CompleteWithCallback(ioResult, (uint)numberOfBytesTransferred, overlapped);
        }
Esempio n. 6
0
 private static void DispatchCallback(IntPtr instance, IntPtr context, IntPtr work)
 {
     RuntimeThread.InitializeThreadPoolThread();
     Debug.Assert(s_work == work);
     ThreadPoolWorkQueue.Dispatch();
 }
Esempio n. 7
0
 private static void TimerCallback(IntPtr instance, IntPtr context, IntPtr timer)
 {
     RuntimeThread.InitializeThreadPoolThread();
     Instance.FireNextTimers();
 }