From b198fd8be71a9c14b523a1263f5659436b339000 Mon Sep 17 00:00:00 2001 From: MrArrowww Date: Thu, 25 Jun 2026 14:58:04 +0330 Subject: [PATCH] Fix TCPing tests not stopping when ESC is pressed (#9623) --- .../ServiceLib/Services/SpeedtestService.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs index a66fef63..1adf3713 100644 --- a/v2rayN/ServiceLib/Services/SpeedtestService.cs +++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs @@ -46,7 +46,7 @@ public class SpeedtestService(Config config, Func updateF switch (actionType) { case ESpeedActionType.Tcping: - await RunTcpingAsync(lstSelected); + await RunTcpingAsync(lstSelected, exitLoopKey); break; case ESpeedActionType.Realping: @@ -135,16 +135,28 @@ public class SpeedtestService(Config config, Func updateF return lstSelected; } - private async Task RunTcpingAsync(List selecteds) + private async Task RunTcpingAsync(List selecteds, string exitLoopKey) { var pageSize = Math.Min(selecteds.Count, _speedTestPageSize); var lstBatch = GetTestBatchItem(selecteds, pageSize); foreach (var lst in lstBatch) { + if (ShouldStopTest(exitLoopKey)) + { + await UpdateFunc("", ResUI.SpeedtestingSkip); + return; + } + List tasks = []; + foreach (var it in lst) { + if (ShouldStopTest(exitLoopKey)) + { + return; + } + tasks.Add(Task.Run(async () => { try @@ -160,7 +172,14 @@ public class SpeedtestService(Config config, Func updateF } })); } + await Task.WhenAll(tasks); + + if (ShouldStopTest(exitLoopKey)) + { + return; + } + await Task.Delay(_delayInterval); } }