We use the following function to test internet connectivity every 5 seconds. But in some part of the world, this function always returns false. Now, the problem is we can set a proxy server in Windows to make this function return true, but we have to restart Windows after setting up the proxy server to make this happen. Is there any way to make the client.GetAsync() detect the proxy server settings instantly without restart Windows?
public static async Task<bool> TestInternetConnectivity()
{
try
{
var client = new HttpClient();
var response = await client.GetAsync($"http://www.msftconnecttest.com/connecttest.txt");
var result = await response.Content.ReadAsStringAsync();
if (!string.Equals(result, "Microsoft Connect Test"))
return false;
return true;
}
catch (Exception)
{
return false;
}
}

new HttpClient()on each call, use theIHttpClientFactory? Not sure if that fixes the problem, but it's an easy enough change to just give it a try.HttpClient?