Esempio n. 1
0
        public void Run()
        {
            if (m_bStartConnect && !m_bConnect)
            {
                if (System.Environment.TickCount - m_nReconnectTick > m_nReconnectTime)
                {
                    if (m_TcpClient.Connect(m_sIP, m_nPort))
                    {
                        m_bConnect = true;
                    }
                    else
                    {
                        //永远不会走到这里的,黑人问号脸-。-
                        ClientSocketEvent e = new ClientSocketEvent();
                        e.connId = this.ConnectionId;
                        e.type   = ClientSocketEvent.CLIENTSOCKETEVENT_TYPE.ONRECONNECT;
                        m_OnSocket.Invoke(e);
                    }
                    m_nReconnectTick = System.Environment.TickCount;
                }
            }


            //交换数据队列
            lock (m_LockObject)
            {
                if (m_Queue.Count > 0)
                {
                    for (int i = 0; i < m_Queue.Count; i++)
                    {
                        m_TempQueue.Enqueue(m_Queue.Dequeue());
                    }
                }
            }
            if (m_TempQueue.Count > 0)
            {
                for (int i = 0; i < m_TempQueue.Count; i++)
                {
                    m_OnSocket.Invoke(m_TempQueue.Dequeue());
                }
            }
        }
Esempio n. 2
0
 public void Run()
 {
     //交换数据队列
     lock (m_LockObject)
     {
         if (m_Queue.Count > 0)
         {
             for (int i = 0; i < m_Queue.Count; i++)
             {
                 m_TempQueue.Enqueue(m_Queue.Dequeue());
             }
         }
     }
     if (m_TempQueue.Count > 0)
     {
         while (m_TempQueue.Count > 0)
         {
             m_OnSocket.Invoke(m_TempQueue.Dequeue());
         }
     }
 }