Ejemplo n.º 1
0
 // 线程池销毁线程
 private void DestroyThread(ThreadPoolThread thread)
 {
     if (thread == null)
     {
         return;
     }
     thread.Dispose();
     m_Pool.Push(thread);
 }
Ejemplo n.º 2
0
 // 主线程调用
 private static void OnMainThreadEnd(ThreadPoolThread thread)
 {
     if (thread == null)
     {
         return;
     }
     // 线程回线程池
     MainThreadPool.DestroyThread(thread);
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }