public static void Run(MonitorSet monitorSet) { Trace.Listeners.Add(new ConsoleTraceListener()); Console.WriteLine("Starting Monitors..."); // Start the runners var cancelSource = new CancellationTokenSource(); var task = monitorSet .Run(new ColoredConsoleEventReporter(), cancelSource.Token) .ContinueWith(t => { if (t.IsFaulted) { Console.WriteLine("An exception occurred!"); Console.WriteLine(t.Exception.GetBaseException()); } }); // Wait for cancellation from the user Console.WriteLine("Monitors Running. Press ENTER to shut down"); Console.ReadLine(); Console.WriteLine("Shutting down"); // Cancel the task and wait for completion cancelSource.Cancel(); task.Wait(); }