예제 #1
0
        /// <summary>
        /// 心跳超时检测(超过3分钟没有收到心跳数据则断掉连接)
        /// </summary>
        private void KeepAliveTimeoutTestThread()
        {
            Thread thread = new Thread(KeepAliveTimeoutTest)
            {
                IsBackground = true
            };

            thread.Start(30000);
            OnMessage?.BeginInvoke(":启动下发心跳超时检测线程", "1", this, null, null);
        }
예제 #2
0
 /// <summary>
 /// 心跳超时检测(超过3分钟没有收到心跳数据则断掉连接)
 /// </summary>
 /// <param name="inteval">间隔(毫秒)</param>
 private void KeepAliveTimeoutTest(object inteval)
 {
     while (_IsRun)
     {
         DateTime time = DateTime.Now;
         // 如果下发心跳超过3分钟,则断开重连
         if ((time - this._LastKeepAliveTime).TotalMinutes > 3)
         {
             OnMessage?.BeginInvoke(":下发心跳超时(3分钟)断开重连...", "1", null, null, null);
             this.Close(true);
             break;
         }
         Thread.Sleep(Convert.ToInt32(inteval));
     }
     try
     {
         Thread.CurrentThread.Abort();
     }
     catch
     {
         // ignored
     }
 }