static void Main(string[] args) { Console.Clear(); Console.SetCursorPosition(0, 3); Console.WriteLine("To exit the program use Alt+E shortcut!"); Console.SetCursorPosition(0, 5); Timer timer = new Timer(); timer.RaiseEvent += DisplayTime; timer.Start(); while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.E && key.Modifiers == ConsoleModifiers.Alt) { Console.WriteLine(); break; } if (key.Key == ConsoleKey.Enter) { Console.WriteLine(); } } } timer.Stop(); }
static void Main() { var publisher = new Timer(); var subscriber = new TimerSubscriber(); publisher.Timed += subscriber.OnTimerChange; publisher.RunTimer(10); }