/// <summary> /// If the AlarmTimer is enabled this method is called every minute. If the current /// time is equal to the Alarm Time (with an accuracy of 1 minute) then the events /// are fired and the Alarm is disabled. /// </summary> /// <param name="alarm">The AlarmTimer used</param> /// <param name="e">The internal timer's EventArgs</param> private void tmrAlarm_Elapsed(object alarm, ElapsedEventArgs e) { if (enabled) { DateTime now = DateTime.Now; if ((alarmTime.Hour == now.Hour) && (alarmTime.Minute == now.Minute)) { AlarmTriggerEventArgs alarmeventargs = new AlarmTriggerEventArgs(alarmTime); //Console.WriteLine("in last tick, onalarmtriggernull={0}",OnAlarmTrigger.ToString()); if (OnAlarmTrigger != null) //if there are observers attached { OnAlarmTrigger(this, alarmeventargs); } if (OnAlarmBell != null) { OnAlarmBell(this, EventArgs.Empty); } //no more events must be raised, so stop the Timer alarmTimer.Stop(); } /*else * { * Console.WriteLine("wait another 60secs"); * }*/ } }
/// <summary> /// If the AlarmTimer is enabled this method is called every minute. If the current /// time is equal to the Alarm Time (with an accuracy of 1 minute) then the events /// are fired and the Alarm is disabled. /// </summary> /// <param name="alarm">The AlarmTimer used</param> /// <param name="e">The internal timer's EventArgs</param> private void tmrAlarm_Elapsed(object alarm, ElapsedEventArgs e) { if (enabled) { DateTime now=DateTime.Now; if ((alarmTime.Hour==now.Hour)&&(alarmTime.Minute==now.Minute)) { AlarmTriggerEventArgs alarmeventargs=new AlarmTriggerEventArgs(alarmTime); //Console.WriteLine("in last tick, onalarmtriggernull={0}",OnAlarmTrigger.ToString()); if (OnAlarmTrigger!=null)//if there are observers attached { OnAlarmTrigger(this,alarmeventargs); } if(OnAlarmBell!=null) { OnAlarmBell(this,EventArgs.Empty); } //no more events must be raised, so stop the Timer alarmTimer.Stop(); } /*else { Console.WriteLine("wait another 60secs"); }*/ } }