internal static bool Dispatch()
        {
            ThreadPoolWorkQueue workQueue = ThreadPoolGlobals.workQueue;
            int tickCount = Environment.TickCount;

            workQueue.MarkThreadRequestSatisfied();
            workQueue.loggingEnabled = FrameworkEventSource.Log.IsEnabled(EventLevel.Verbose, (EventKeywords)18L);
            bool flag = true;
            IThreadPoolWorkItem threadPoolWorkItem = null;

            try
            {
                ThreadPoolWorkQueueThreadLocals tl = workQueue.EnsureCurrentThreadHasQueue();
                while ((long)(Environment.TickCount - tickCount) < (long)((ulong)ThreadPoolGlobals.tpQuantum))
                {
                    try
                    {
                    }
                    finally
                    {
                        bool flag2 = false;
                        workQueue.Dequeue(tl, out threadPoolWorkItem, out flag2);
                        if (threadPoolWorkItem == null)
                        {
                            flag = flag2;
                        }
                        else
                        {
                            workQueue.EnsureThreadRequested();
                        }
                    }
                    if (threadPoolWorkItem == null)
                    {
                        return(true);
                    }
                    if (workQueue.loggingEnabled)
                    {
                        FrameworkEventSource.Log.ThreadPoolDequeueWorkObject(threadPoolWorkItem);
                    }
                    if (ThreadPoolGlobals.enableWorkerTracking)
                    {
                        bool flag3 = false;
                        try
                        {
                            try
                            {
                            }
                            finally
                            {
                                ThreadPool.ReportThreadStatus(true);
                                flag3 = true;
                            }
                            threadPoolWorkItem.ExecuteWorkItem();
                            threadPoolWorkItem = null;
                            goto IL_A6;
                        }
                        finally
                        {
                            if (flag3)
                            {
                                ThreadPool.ReportThreadStatus(false);
                            }
                        }
                        goto IL_9E;
                    }
                    goto IL_9E;
IL_A6:
                    if (!ThreadPool.NotifyWorkItemComplete())
                    {
                        return(false);
                    }
                    continue;
IL_9E:
                    threadPoolWorkItem.ExecuteWorkItem();
                    threadPoolWorkItem = null;
                    goto IL_A6;
                }
                return(true);
            }
            catch (ThreadAbortException tae)
            {
                if (threadPoolWorkItem != null)
                {
                    threadPoolWorkItem.MarkAborted(tae);
                }
                flag = false;
            }
            finally
            {
                if (flag)
                {
                    workQueue.EnsureThreadRequested();
                }
            }
            return(true);
        }
Example #2
0
        internal static bool Dispatch()
        {
            ThreadPoolWorkQueue threadPoolWorkQueue = ThreadPoolGlobals.workQueue;
            int tickCount = Environment.TickCount;

            threadPoolWorkQueue.MarkThreadRequestSatisfied();
            threadPoolWorkQueue.loggingEnabled = FrameworkEventSource.Log.IsEnabled(EventLevel.Verbose, (EventKeywords)18);
            bool flag1 = true;
            IThreadPoolWorkItem callback = (IThreadPoolWorkItem)null;

            try
            {
                ThreadPoolWorkQueueThreadLocals tl = threadPoolWorkQueue.EnsureCurrentThreadHasQueue();
                while ((long)(Environment.TickCount - tickCount) < (long)ThreadPoolGlobals.tpQuantum)
                {
                    try
                    {
                    }
                    finally
                    {
                        bool missedSteal = false;
                        threadPoolWorkQueue.Dequeue(tl, out callback, out missedSteal);
                        if (callback == null)
                        {
                            flag1 = missedSteal;
                        }
                        else
                        {
                            threadPoolWorkQueue.EnsureThreadRequested();
                        }
                    }
                    if (callback == null)
                    {
                        return(true);
                    }
                    if (threadPoolWorkQueue.loggingEnabled)
                    {
                        FrameworkEventSource.Log.ThreadPoolDequeueWorkObject((object)callback);
                    }
                    if (ThreadPoolGlobals.enableWorkerTracking)
                    {
                        bool flag2 = false;
                        try
                        {
                            try
                            {
                            }
                            finally
                            {
                                ThreadPool.ReportThreadStatus(true);
                                flag2 = true;
                            }
                            callback.ExecuteWorkItem();
                            callback = (IThreadPoolWorkItem)null;
                        }
                        finally
                        {
                            if (flag2)
                            {
                                ThreadPool.ReportThreadStatus(false);
                            }
                        }
                    }
                    else
                    {
                        callback.ExecuteWorkItem();
                        callback = (IThreadPoolWorkItem)null;
                    }
                    if (!ThreadPool.NotifyWorkItemComplete())
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (ThreadAbortException ex)
            {
                if (callback != null)
                {
                    callback.MarkAborted(ex);
                }
                flag1 = false;
            }
            finally
            {
                if (flag1)
                {
                    threadPoolWorkQueue.EnsureThreadRequested();
                }
            }
            return(true);
        }
Example #3
0
        internal static bool Dispatch()
        {
            bool flag4;
            int  tickCount = Environment.TickCount;

            ThreadPoolGlobals.workQueue.MarkThreadRequestSatisfied();
            bool flag = true;
            IThreadPoolWorkItem callback = null;

            try
            {
                ThreadPoolWorkQueueThreadLocals tl = ThreadPoolGlobals.workQueue.EnsureCurrentThreadHasQueue();
                while ((Environment.TickCount - tickCount) < ThreadPoolGlobals.tpQuantum)
                {
                    try
                    {
                    }
                    finally
                    {
                        bool missedSteal = false;
                        ThreadPoolGlobals.workQueue.Dequeue(tl, out callback, out missedSteal);
                        if (callback == null)
                        {
                            flag = missedSteal;
                        }
                        else
                        {
                            ThreadPoolGlobals.workQueue.EnsureThreadRequested();
                        }
                    }
                    if (callback == null)
                    {
                        return(true);
                    }
                    if (ThreadPoolGlobals.enableWorkerTracking)
                    {
                        bool flag3 = false;
                        try
                        {
                            try
                            {
                            }
                            finally
                            {
                                ThreadPool.ReportThreadStatus(true);
                                flag3 = true;
                            }
                            callback.ExecuteWorkItem();
                            callback = null;
                        }
                        finally
                        {
                            if (flag3)
                            {
                                ThreadPool.ReportThreadStatus(false);
                            }
                        }
                    }
                    else
                    {
                        callback.ExecuteWorkItem();
                        callback = null;
                    }
                    if (!ThreadPool.NotifyWorkItemComplete())
                    {
                        return(false);
                    }
                }
                flag4 = true;
            }
            catch (ThreadAbortException exception)
            {
                if (callback != null)
                {
                    callback.MarkAborted(exception);
                }
                flag = false;
                throw;
            }
            finally
            {
                if (flag)
                {
                    ThreadPoolGlobals.workQueue.EnsureThreadRequested();
                }
            }
            return(flag4);
        }