static async Task Main(string[] args) { TrafficLight trafficLight = new TrafficLight(4, 3, 2); TrafficLight trafficLight1 = new TrafficLight(18, 15, 14); TrafficLight trafficLight2 = new TrafficLight(22, 27, 17); TrafficLight trafficLight3 = new TrafficLight(11, 9, 10); Console.WriteLine("Welcome to traffic light controller"); using (var trafficLightController = new TrafficLightController(trafficLight3, TrafficPhase.RedPhase)) { trafficLightController.TrafficLightStatusMessageEvent += StatusMessageEvent; Console.WriteLine("Initial Staus:"); PrintStatus(trafficLightController); Console.WriteLine("Start task"); CancellationTokenSource tokenSource = new CancellationTokenSource(); var task = trafficLightController.StartTrafficLight(tokenSource.Token); Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs args) => { tokenSource.Cancel(); task.Wait(); Console.WriteLine($"Task completed: {task.IsCompleted}"); Console.WriteLine("Bye"); }; Console.WriteLine($"Task completed: {task.IsCompleted}"); var result = await task; Console.WriteLine($"Result: {result}"); Console.ReadKey(); } Console.ReadKey(); }