Пример #1
0
        private bool BeginConnect(int maxConnectNum)
        {
            this._timerTrigger = new MinHeap <SocketClientInfo>(maxConnectNum);
            string[] aryIPPort = tb_IPPort.Text.Split(':');
            this.m_strIP = aryIPPort[0];
            this.m_nPort = Convert.ToInt32(aryIPPort[1]);

            for (int i = 0; i < maxConnectNum; i++)
            {
                SocketClient client = new SocketClient(3 * m_nMinReceiveSize, 2 * m_nMinSendSize, m_strIP, m_nPort);
                client.eventPrintMessage += new EventHandler <SessionEventArgs>(this.OnEventPrintMessage);
                client.parent             = this;

                SocketClientInfo socketClientInfo = new SocketClientInfo();
                socketClientInfo.timeOutCallBack = client.TimerHandle;
                socketClientInfo.Weight          = TimeHandle.ConvertDatetimeToSec(DateTime.Now) + socketClientInfo.timeSpan;
                this._timerTrigger.Push(socketClientInfo);
            }

            ThreadHandle.StartBackgroundThread(new ThreadStart(this.MainLoop), null);
            return(true);
        }
Пример #2
0
 private void MainLoop()
 {
     while (Interlocked.Read(ref this.m_lngRun) > 0)
     {
         try
         {
             UInt32 timestamp = TimeHandle.ConvertDatetimeToSec(DateTime.Now);
             if (this._timerTrigger.Count > 0 && this._timerTrigger.Root.Weight <= timestamp)
             {
                 this._timerTrigger.Root.timeOutCallBack();
                 this._timerTrigger.ChangeWeight(this._timerTrigger.Root.HeapIndex, timestamp + this._timerTrigger.Root.timeSpan);
             }
         }
         catch
         {
         }
         finally
         {
             Thread.Sleep(10);
         }
     }
 }