mirror of
https://github.com/2dust/v2rayN.git
synced 2025-11-29 03:02:53 +00:00
Fix speedtest termination latency
This commit is contained in:
parent
8ec6d70d2b
commit
410b1b3b53
1 changed files with 32 additions and 15 deletions
|
|
@ -19,7 +19,7 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
|
||||||
|
|
||||||
public void ExitLoop()
|
public void ExitLoop()
|
||||||
{
|
{
|
||||||
if (_lstExitLoop.Count > 0)
|
if (!_lstExitLoop.IsEmpty)
|
||||||
{
|
{
|
||||||
_ = UpdateFunc("", ResUI.SpeedtestingStop);
|
_ = UpdateFunc("", ResUI.SpeedtestingStop);
|
||||||
|
|
||||||
|
|
@ -27,6 +27,11 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool ShouldStopTest(string exitLoopKey)
|
||||||
|
{
|
||||||
|
return !_lstExitLoop.Any(p => p == exitLoopKey);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task RunAsync(ESpeedActionType actionType, List<ProfileItem> selecteds)
|
private async Task RunAsync(ESpeedActionType actionType, List<ProfileItem> selecteds)
|
||||||
{
|
{
|
||||||
var exitLoopKey = Utils.GetGuid(false);
|
var exitLoopKey = Utils.GetGuid(false);
|
||||||
|
|
@ -157,7 +162,7 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
|
||||||
var pageSizeNext = pageSize / 2;
|
var pageSizeNext = pageSize / 2;
|
||||||
if (lstFailed.Count > 0 && pageSizeNext > 0)
|
if (lstFailed.Count > 0 && pageSizeNext > 0)
|
||||||
{
|
{
|
||||||
if (_lstExitLoop.Any(p => p == exitLoopKey) == false)
|
if (ShouldStopTest(exitLoopKey))
|
||||||
{
|
{
|
||||||
await UpdateFunc("", ResUI.SpeedtestingSkip);
|
await UpdateFunc("", ResUI.SpeedtestingSkip);
|
||||||
return;
|
return;
|
||||||
|
|
@ -195,6 +200,12 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ShouldStopTest(exitLoopKey))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
tasks.Add(Task.Run(async () =>
|
tasks.Add(Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await DoRealPing(it);
|
await DoRealPing(it);
|
||||||
|
|
@ -223,7 +234,7 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
|
||||||
List<Task> tasks = new();
|
List<Task> tasks = new();
|
||||||
foreach (var it in selecteds)
|
foreach (var it in selecteds)
|
||||||
{
|
{
|
||||||
if (_lstExitLoop.Any(p => p == exitLoopKey) == false)
|
if (ShouldStopTest(exitLoopKey))
|
||||||
{
|
{
|
||||||
await UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
|
await UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -239,13 +250,20 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
|
||||||
if (processService is null)
|
if (processService is null)
|
||||||
{
|
{
|
||||||
await UpdateFunc(it.IndexId, "", ResUI.FailedToRunCore);
|
await UpdateFunc(it.IndexId, "", ResUI.FailedToRunCore);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
|
|
||||||
var delay = await DoRealPing(it);
|
var delay = await DoRealPing(it);
|
||||||
if (blSpeedTest)
|
if (blSpeedTest)
|
||||||
{
|
{
|
||||||
|
if (ShouldStopTest(exitLoopKey))
|
||||||
|
{
|
||||||
|
await UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (delay > 0)
|
if (delay > 0)
|
||||||
{
|
{
|
||||||
await DoSpeedTest(downloadHandle, it);
|
await DoSpeedTest(downloadHandle, it);
|
||||||
|
|
@ -256,7 +274,6 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logging.SaveLog(_tag, ex);
|
Logging.SaveLog(_tag, ex);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue