public void StartHeatBeat() { if (_running) { return; } _running = true; var path = Directory.GetCurrentDirectory() + "\\Config" + "\\" + "ping.txt"; if (System.IO.File.Exists(path)) { var file = Wlst.Cr.Coreb.Servers.WriteFile.ReadFiles(path); foreach (var f in file) { var sps = f.Split('-'); if (sps.Length < 2) { continue; } int x = 0; if (Int32.TryParse(sps [1], out x)) { if (x > 0 && x < 60) { SndClientBeatTime = x; break; } } } } _schedule = new System.Timers.Timer(SndClientBeatTime * 1000); //实例化Timer类,设置间隔时间为1000毫秒; _schedule.Elapsed += new System.Timers.ElapsedEventHandler(Schedule); //到达时间的时候执行事件; _schedule.AutoReset = true; //设置是执行一次(false)还是一直执行(true); _schedule.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件; _schedule.Start(); ProtocolServer.RegistProtocol( Wlst.Sr.ProtocolPhone.LxSys.wst_heart_beating, //.ClientPart.wlst_server_ans_clinet_heat_beating, action, typeof(KeepAliveSocket), this); DtClientHeatBeatingLastTime = new DateTime(1999, 1, 1); }
public void RegistProtocol(MsgWithMobile cmd, Action <string, MsgWithMobile> action, bool runInUiThread = false) { ProtocolServer.RegistProtocol(cmd, action, this.GetType(), this, runInUiThread); }