taskexecutionworker.cs

来自「破解的飞信源代码」· CS 代码 · 共 108 行

CS
108
字号
namespace NCindy.Threading
{
    using System;
    using System.Threading;

    internal class TaskExecutionWorker
    {
        private bool isRunning;
        private readonly NCindy.Threading.ThreadPool parentPool;
        public Thread thread;

        public TaskExecutionWorker(NCindy.Threading.ThreadPool parentPool)
        {
            this.parentPool = parentPool;
        }

        private void CheckShutdownComplete()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        private void CheckStartupComplete()
        {
        }

        internal void ExecutionLoop()
        {
            int num;
            this.CheckStartupComplete();
        Label_0006:
            num = 0;
            ITask task = null;
            try
            {
                while (true)
                {
                    if (num == 0)
                    {
                        if (this.thread == null)
                        {
                            break;
                        }
                        this.WaitForTask();
                    }
                    num = 0;
                    int num2 = this.parentPool.taskQueueList.get_Count();
                    for (int i = 0; i < num2; i++)
                    {
                        if (num2 != this.parentPool.taskQueueList.get_Count())
                        {
                            break;
                        }
                        try
                        {
                            this.parentPool.taskQueueList.get_Item(i);
                        }
                        catch
                        {
                            break;
                        }
                    }
                }
                this.CheckShutdownComplete();
            }
            catch (Exception exception)
            {
                this.HandleException(task, exception);
                goto Label_0006;
            }
        }

        private void HandleException(ITask task, Exception exception)
        {
        }

        internal void Signal()
        {
            if (!this.isRunning)
            {
                lock (this)
                {
                    if (!this.isRunning)
                    {
                        Monitor.Pulse(this);
                    }
                }
            }
        }

        private void WaitForTask()
        {
            if (this.parentPool.pendingTaskCount == 0)
            {
                this.isRunning = false;
                lock (this)
                {
                    if (this.parentPool.pendingTaskCount == 0)
                    {
                        Monitor.Wait(this);
                    }
                }
                this.isRunning = true;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?