Пример #1
0
 // 线程池销毁线程
 private void DestroyThread(ThreadPoolThread thread)
 {
     if (thread == null)
     {
         return;
     }
     thread.Dispose();
     m_Pool.Push(thread);
 }
Пример #2
0
 // 主线程调用
 private static void OnMainThreadEnd(ThreadPoolThread thread)
 {
     if (thread == null)
     {
         return;
     }
     // 线程回线程池
     MainThreadPool.DestroyThread(thread);
 }
Пример #3
0
        public void Clear()
        {
            if (m_Pool.Count <= 0)
            {
                return;
            }
            ThreadPoolThread thread = m_Pool.Pop();

            while (thread != null)
            {
                thread.Dispose();
                if (m_Pool.Count <= 0)
                {
                    break;
                }
                thread = m_Pool.Pop();
            }
            m_Pool.Clear();
        }
Пример #4
0
        // 线程池创建线程
        private ThreadPoolThread CreateThread(Action <System.Object> onThreadProcess, System.Object state = null,
                                              Action <ThreadPoolThread> onMainThreadEnd = null)
        {
            ThreadPoolThread ret = null;

            if (m_Pool.Count > 0)
            {
                ret = m_Pool.Pop();
            }
            if (ret == null)
            {
                ret = new ThreadPoolThread(onThreadProcess, state, onMainThreadEnd);
            }
            else
            {
                ret.Init(onThreadProcess, state, onMainThreadEnd);
            }
            // 线程开始
            ret.Start();
            return(ret);
        }