Example #1
0
        /// <summary>
        /// 检测心跳包,20秒钟检测
        /// </summary>
        private void CheckHeartbeat()
        {
            new Thread(() =>
            {
                while (!isEnd)
                {
                    Thread.Sleep(10000);
                    long currentTick = DateTime.Now.Ticks;
                    if (lastTick > 0 && currentTick - lastTick > 200000000)
                    {
                        if (AppConfigInfos.IceConnect)
                        {
                            IceHelper.Instance.Dispose();

                            Modules.ForEach(p => p.DisConnectNetWork());
                            EventManager.Instance.DisConnectNetWork();

                            LogHelper.Instance.WirteLog("Heartbeat Start Reconnection", LogLevel.LogDebug);
                        }

                        AppConfigInfos.IceConnect = IceHelper.Instance.Init();

                        // 更新状态
                        if (AppConfigInfos.IceConnect)
                        {
                            LogHelper.Instance.WirteLog("Heartbeat  Reconnection Succeed", LogLevel.LogDebug);

                            dataResponsible.SendHeartbeat();

                            Modules.ForEach(p => p.ConnectNetWork(dataResponsible));
                            EventManager.Instance.ConnectNetWork(dataResponsible);
                        }
                        else
                        {
                            LogHelper.Instance.WirteLog("Heartbeat  Reconnection Failed", LogLevel.LogDebug);
                            AppConfigInfos.AppStateInfos.ServerState     = "1";
                            AppConfigInfos.AppStateInfos.DataBaseState   = "1";
                            AppConfigInfos.AppStateInfos.ServerMsgCode   = "1";
                            AppConfigInfos.AppStateInfos.DataBaseMsgCode = "1";
                        }
                    }
                }
            })
            {
                IsBackground = true
            }.Start();
        }