public static async Task WriteFacts(FactSubject subject, int repeatSeconds, ConsoleColor consoleColor) { AnimalFacts facts = new AnimalFacts(HttpClient); while (true) { var fact = await facts.GetFact(new AnimalFactQuery(subject)); Console.ForegroundColor = consoleColor; Console.WriteLine(fact.ToString(), consoleColor); await Task.Delay(TimeSpan.FromSeconds(repeatSeconds)); } }
public static async Task WriteFacts() { AnimalFacts facts = new AnimalFacts(HttpClient); TextFileWriter writer = new TextFileWriter(WRITEFILE); while (true) { var fact = await facts.GetFact(new AnimalFactQuery(FactSubject.Cat)); bool successfullyWritten = await writer.CreateOrAppend(fact.ToString()); Console.WriteLine($"Fact {fact.Id} written to file. Successful: {successfullyWritten}"); await Task.Delay(TimeSpan.FromSeconds(10)); } }