Retry pattern in C#

  • Thread starter Thread starter AndriannaTs
  • Start date Start date
A

AndriannaTs

Guest
How to use Retry Pattern in the following request.

private async static Task loginUser()
{
bool loginFlag = false,
userNameFlag = false,
passwordFlag = false;

string userName, userPassword;

while (loginFlag != true)
{
Console.WriteLine("enter username");
userName = Console.ReadLine();

using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:12345");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/..."));
HttpResponseMessage response = await client.GetAsync("api/login");

if (response.IsSuccessStatusCode)
Console.WriteLine("Welcome ");
}
}
}

Continue reading...
 
Back
Top