I have a program which does a simple http get in an async call and writes it to the console:
using System;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
namespace Hello
{
class Program
{
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
await ProcessRepositories();
}
private static async Task ProcessRepositories()
{
client.DefaultRequestHeaders.Accept.Clear();
var stringTask = client.GetStringAsync("https://localhost:8080");
var msg = await stringTask;
Console.Write(msg);
}
}
}
How could I repeat the whole process to make it write it to the console until a button is pressed?
3
Answers
You can use Polly library for such calls. Do not use infinity loop, it is bad practice.
Here is an example about retry with exponential backoff.
To keep processing data until a key is pressed;