public B链路监控(M链路监控配置 __配置) { 配置 = __配置; Task.Factory.StartNew(() => { while (true) { var temp = new Dictionary <string, string>(配置.IP列表); foreach (var __kv in temp) { var __地址 = __kv.Key; M链路状态 __状态 = null; if (_缓存.ContainsKey(__地址)) { __状态 = _缓存[__地址]; } else { __状态 = new M链路状态 { 地址 = __地址, 通 = true, 描述 = __kv.Value }; _缓存[__地址] = __状态; } var __Ping = new Ping(); __Ping.PingCompleted += PingCompletedCallback; try { if (Program.IsWindows) { __Ping.SendAsync(__地址, 配置.超时, new Tuple <string, Ping, M链路状态>(__地址, __Ping, __状态)); } else { __Ping.SendAsync(Dns.GetHostAddresses(__地址)[0], 配置.超时, new Tuple <string, Ping, M链路状态>(__地址, __Ping, __状态)); } } catch (Exception) { 处理Ping结果(__地址, __Ping, __状态, false); } } Thread.Sleep(配置.频率); } }); }
public void 修改配置(M链路监控配置 __配置) { 配置 = __配置; _缓存.Clear(); }