private static async Task RunTeleprompter() { var config = new TelePrompterConfig(); var displayTask = ShowTeleprompter(config); var speedTask = GetInput(config); await Task.WhenAny(displayTask, speedTask); }
private static async Task ShowTeleprompter(TelePrompterConfig config) { var words = ReadFrom("SampleQuotes.txt"); foreach (var word in words) { Console.Write(word); if (!string.IsNullOrWhiteSpace(word)) { await Task.Delay(config.DelayInMilliseconds); } } config.SetDone(); }
private static async Task GetInput(TelePrompterConfig config) { Action work = () => { do { var key = Console.ReadKey(true); if (key.KeyChar == '>') { config.UpdateDelay(-10); } else if (key.KeyChar == '<') { config.UpdateDelay(10); } } while (!config.Done); }; await Task.Run(work); }