2dust
2024-10-15 09:31:30 +08:00
parent 24afe8bde4
commit fd7cf164ff
12 changed files with 58 additions and 19 deletions
@@ -100,7 +100,7 @@ namespace ServiceLib.Services
};
HttpClient client = new(webRequestHandler);
HttpResponseMessage response = await client.GetAsync(url);
var response = await client.GetAsync(url);
if (response.StatusCode == HttpStatusCode.Redirect && response.Headers.Location is not null)
{
return response.Headers.Location.ToString();
@@ -253,15 +253,12 @@ namespace ServiceLib.Services
{
try
{
if (webProxy == null)
{
webProxy = GetWebProxy(true);
}
webProxy ??= GetWebProxy(true);
try
{
var config = AppHandler.Instance.Config;
int responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10);
var responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10);
return responseTime;
}
catch (Exception ex)
@@ -279,7 +276,7 @@ namespace ServiceLib.Services
public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int downloadTimeout)
{
int responseTime = -1;
var responseTime = -1;
try
{
using var cts = new CancellationTokenSource();
@@ -290,8 +287,8 @@ namespace ServiceLib.Services
UseProxy = webProxy != null
});
List<int> oneTime = [];
for (int i = 0; i < 2; i++)
List<int> oneTime = new();
for (var i = 0; i < 2; i++)
{
var timer = Stopwatch.StartNew();
await client.GetAsync(url, cts.Token);