public void reConnectServer(object source, System.Timers.ElapsedEventArgs e) { lock (this) { if (!communicationLib.IsConnect()) { if (!communicationLib.StarSevice(aConfig.atsServerPort1, aConfig.atsServerIP1, 4096 * 2, 0)) { communicationLib.StarSevice(aConfig.atsServerPort2, aConfig.atsServerIP2, 4096 * 2, 0); } } return; } }
private void InitLib() { configLib = new Config(); aConfig = configLib.getConfigObj(); atsLib = new ATSSend(aConfig.switchBetweenChineseAndEnglis); atsLib.initATSLib(aConfig.sendIP, aConfig.sendPort, 30, aConfig.pisServerIP1, aConfig.pisServerPort1); logicLib = new Logic(aConfig.confgStationList.Count); communicationLib = new communication(); if (!communicationLib.StarSevice(aConfig.atsServerPort1, aConfig.atsServerIP1, 4096 * 2, 0)) { // 如果备也连接失败开户定时器每隔2秒重连 // 实例化Timer类,设置间隔时间为10000毫秒; if (connectTimer == null) { connectTimer = new System.Timers.Timer(5000); // 到达时间的时候执行事件 获取中央ATS-列车状态; connectTimer.Elapsed += new System.Timers.ElapsedEventHandler(reConnectServer); // 设置是执行一次(false)还是一直执行(true); connectTimer.AutoReset = true; // 是否执行System.Timers.Timer.Elapsed事件; connectTimer.Enabled = true; } } communicationLib.recvCommChanged += CommunicationLib_recvCommChanged; communicationLib.disConnectChanged += CommunicationLib_disConnectChanged; // 处理数据线程 Thread dataThread = new Thread(new ParameterizedThreadStart(logicDataThread)); dataThread.Start((Object)this); }