private void Scanning() { var config = JsonConvert.DeserializeObject <DepConfig>(File.ReadAllText(depDescFile)); List <int> structs = new List <int>(config.structIds); double interval = Convert.ToDouble(config.warninterval); DateTime thisTime = DateTime.Now; foreach (var structId in structs) { try { List <int> senlst = SqlDal.GetAllSensorIds(structId); var ds = SqlDal.GetAllSensorData(senlst, thisTime.AddMinutes(0 - interval), thisTime); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { SqlDal.InsertWarningMsg(structId, senlst); continue; } foreach (var senId in senlst) { try { if (!senLastTimes.ContainsKey(structId)) { senLastTimes.TryAdd(structId, new ConcurrentDictionary <int, Sensor>()); } if (!senLastTimes[structId].ContainsKey(senId)) { senLastTimes[structId].TryAdd(senId, new Sensor { SensorId = senId, LastTime = DateTime.Now }); } DateTime time = (from r in ds.Tables[0].AsEnumerable() where r.Field <int>("SensorId") == senId orderby r.Field <DateTime>("CollectTime") descending select r.Field <DateTime>("CollectTime")).FirstOrDefault(); if (time != DateTime.MinValue) { senLastTimes[structId][senId].LastTime = time; } else { SqlDal.InsertWarningMsg(structId, senId); continue; } if ((DateTime.Now - senLastTimes[structId][senId].LastTime).TotalMinutes > interval) { SqlDal.InsertWarningMsg(structId, senId); } } catch (Exception ex) { Log.ErrorFormat("Scanning senlst error : {0}", ex.Message); } } } catch (Exception ex) { Log.ErrorFormat("Scanning structs error : {0}", ex.Message); } } }