// Internal helper method that checks to see if any // objects are subscribed to the event. If any are, // their event handler method will be called through // the multicast delegate. private void RaiseAlarmEvent() { // Make sure to check that there is at least one subscriber! if (OnTimerExpired != null) { // Note that before the event fires, an object of // type TimerEventArgs is created. Then, when the // event is fired, the TimerEventArgs object is // passed along with the sender. TimerEventArgs t = new TimerEventArgs(); OnTimerExpired(this, t); } }
private void DisplayAlarmMessage(object sender, TimerEventArgs e) { // Save the current color of the characters. ConsoleColor originalForeGroundColor = Console.ForegroundColor; // Change the color of the characters to Red. Console.ForegroundColor = ConsoleColor.Red; for (int i = 0; i < 5; i++) { Console.WriteLine("\n{0}: WAKE UP!!!!!!!!!!!", e.AlarmTime); Console.Beep(5000, 500); System.Threading.Thread.Sleep(1000); } // Reset the color of the characters to their original color. Console.ForegroundColor = originalForeGroundColor; }
internal void ShowMessage(object sender, TimerEventArgs e) { // Save the current color of the characters. ConsoleColor originalForeGroundColor = Console.ForegroundColor; // Change the color of the characters to Magenta. Console.ForegroundColor = ConsoleColor.Magenta; for (int i = 0; i < 3; i++) { Console.WriteLine("\n{0}: This is your wakeup call.", e.AlarmTime); Console.Beep(3500, 400); System.Threading.Thread.Sleep(750); } // Reset the color of the characters to their original color. Console.ForegroundColor = originalForeGroundColor; }