private void CheckAlarms() { lock (alarms) { // note that if first alarmtime is larger than now, no other alarms need to be checked, as the list is sorted by date if (alarms.Count == 0) return; if (alarms[0].Time <= DateTime.Now) // at least one alarm should be triggered { AlarmCollection killlist = new AlarmCollection(); for (int i=0; i<alarms.Count; i++) { if (alarms[i].Time < DateTime.Now ) { ExecuteAlarm( alarms[i] ); killlist.Add( alarms[i] ); } } for (int i=0; i<killlist.Count; i++) alarms.Remove(killlist[i]); } } }
public AlarmEngine(int granularity) { this.granularity = granularity; alarms = new AlarmCollection(); }