Beispiel #1
0
        public TcpThread GetThread(int threadID = 0)
        {
            if (m_Stoped)
            {
                return(null);
            }
            if (threadID == 0)
            {
                lock (m_IndexLock) {
                    threadID = m_ThreadIndex++;
                }
                threadID = threadID % m_PoolCount;
            }
            TcpThread thread;

            if (Threads.TryGetValue(threadID, out thread))
            {
                return(thread);
            }

            thread = new TcpThread(threadID);
            if (Threads.TryAdd(threadID, thread))
            {
                thread.Start();
                return(thread);
            }
            return(GetThread(threadID));
        }
Beispiel #2
0
        public void Stop()
        {
            m_Stoped = true;
            var       keys   = Threads.Keys;
            TcpThread thread = null;

            foreach (var key in keys)
            {
                if (Threads.TryRemove(key, out thread))
                {
                    thread.Stop();
                }
            }
            Thread.Sleep(100);
            if (Threads.Count > 0)
            {
                Stop();
            }
        }