⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 directdispatcher.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace NCindy.Session.Dispatcher
{
    using NCindy;
    using System;
    using System.Collections;
    using System.Threading;

    public class DirectDispatcher : IDispatcher
    {
        private static readonly LocalDataStoreSlot local = Thread.AllocateDataSlot();
        public static readonly int NumberOfProcessors = Environment.get_ProcessorCount();
        protected Thread[] workers;

        public DirectDispatcher() : this(GetDefaultThreadsCount())
        {
        }

        public DirectDispatcher(int workerThreadsCount)
        {
        }

        public void Block()
        {
        }

        public void Dispatch(ISession session, SessionEventDispatcher eventObject)
        {
            Queue threadLocalQueue = GetThreadLocalQueue();
            threadLocalQueue.Enqueue(eventObject);
            if (threadLocalQueue.Count <= 1)
            {
                eventObject();
                threadLocalQueue.Dequeue();
                while (threadLocalQueue.Count > 0)
                {
                    SessionEventDispatcher dispatcher = (SessionEventDispatcher) threadLocalQueue.Dequeue();
                    if (dispatcher != null)
                    {
                        dispatcher();
                    }
                }
            }
        }

        protected void DispatchLoop()
        {
        }

        protected static int GetDefaultThreadsCount()
        {
            if (NumberOfProcessors < 2)
            {
                return 2;
            }
            return NumberOfProcessors;
        }

        private static Queue GetThreadLocalQueue()
        {
            Queue data = (Queue) Thread.GetData(local);
            if (data == null)
            {
                data = new Queue();
                Thread.SetData(local, data);
            }
            return data;
        }
    }
}

⌨️ 快捷键说明

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