using HDLMonitorService.Entity; using HDLMonitorService.Helper; using System; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace HDLMonitorService.ServiceMonitor { public class ApiGatewayInfoMonitor { private static int DeviceCacheExCount = 0; public static void monitor() { new Thread(new ThreadStart(() => { while (true) { try { var reqPack = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Json//GatewayReqPack.json"); var result = HttpHp.Post(ConfigurationManager.AppSettings["QueryHomeIdByGateway"], reqPack); if (result == null) { throw new Exception("响应数据异常"); } DeviceCacheExCount = 0; } catch (Exception exc) { DeviceCacheExCount++; if (DeviceCacheExCount == 3) { try { AlarmHp.ApplicationAlarm("AppApi", "warn-system", exc.StackTrace.Substring(0, 200), "114.215.173.87", exc.Message); } catch (Exception ex) { LogHp.WriteLog("App异常", Newtonsoft.Json.JsonConvert.SerializeObject(ex)); } } } Thread.Sleep(1000 * 10); } })) { IsBackground = true }.Start(); } } }