diff --git a/v2rayN/ServiceLib/Manager/ClashApiManager.cs b/v2rayN/ServiceLib/Manager/ClashApiManager.cs index 9147df05..e34f838d 100644 --- a/v2rayN/ServiceLib/Manager/ClashApiManager.cs +++ b/v2rayN/ServiceLib/Manager/ClashApiManager.cs @@ -35,7 +35,7 @@ public sealed class ClashApiManager return null; } - public void ClashProxiesDelayTest(bool blAll, List lstProxy, Action updateFunc) + public void ClashProxiesDelayTest(bool blAll, List lstProxy, Func updateFunc) { Task.Run(async () => { @@ -79,12 +79,12 @@ public sealed class ClashApiManager tasks.Add(Task.Run(async () => { var result = await HttpClientHelper.Instance.TryGetAsync(url); - updateFunc?.Invoke(it, result); + await updateFunc?.Invoke(it, result); })); } await Task.WhenAll(tasks); await Task.Delay(1000); - updateFunc?.Invoke(null, ""); + await updateFunc?.Invoke(null, ""); }); } diff --git a/v2rayN/ServiceLib/Manager/StatisticsManager.cs b/v2rayN/ServiceLib/Manager/StatisticsManager.cs index 69a47856..1e439a7f 100644 --- a/v2rayN/ServiceLib/Manager/StatisticsManager.cs +++ b/v2rayN/ServiceLib/Manager/StatisticsManager.cs @@ -8,14 +8,14 @@ public class StatisticsManager private Config _config; private ServerStatItem? _serverStatItem; private List _lstServerStat; - private Action? _updateFunc; + private Func? _updateFunc; private StatisticsXrayService? _statisticsXray; private StatisticsSingboxService? _statisticsSingbox; private static readonly string _tag = "StatisticsHandler"; public List ServerStat => _lstServerStat; - public async Task Init(Config config, Action updateFunc) + public async Task Init(Config config, Func updateFunc) { _config = config; _updateFunc = updateFunc; @@ -97,9 +97,9 @@ public class StatisticsManager _lstServerStat = await SQLiteHelper.Instance.TableAsync().ToListAsync(); } - private void UpdateServerStatHandler(ServerSpeedItem server) + private async Task UpdateServerStatHandler(ServerSpeedItem server) { - _ = UpdateServerStat(server); + await UpdateServerStat(server); } private async Task UpdateServerStat(ServerSpeedItem server) @@ -123,7 +123,7 @@ public class StatisticsManager server.TodayDown = _serverStatItem.TodayDown; server.TotalUp = _serverStatItem.TotalUp; server.TotalDown = _serverStatItem.TotalDown; - _updateFunc?.Invoke(server); + await _updateFunc?.Invoke(server); } private async Task GetServerStatItem(string indexId) diff --git a/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs b/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs index 82a5330d..d3de6a18 100644 --- a/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs +++ b/v2rayN/ServiceLib/Services/Statistics/StatisticsSingboxService.cs @@ -8,11 +8,11 @@ public class StatisticsSingboxService private readonly Config _config; private bool _exitFlag; private ClientWebSocket? webSocket; - private Action? _updateFunc; + private readonly Func? _updateFunc; private string Url => $"ws://{Global.Loopback}:{AppManager.Instance.StatePort2}/traffic"; private static readonly string _tag = "StatisticsSingboxService"; - public StatisticsSingboxService(Config config, Action updateFunc) + public StatisticsSingboxService(Config config, Func updateFunc) { _config = config; _updateFunc = updateFunc; @@ -90,7 +90,7 @@ public class StatisticsSingboxService { ParseOutput(result, out var up, out var down); - _updateFunc?.Invoke(new ServerSpeedItem() + await _updateFunc?.Invoke(new ServerSpeedItem() { ProxyUp = (long)(up / 1000), ProxyDown = (long)(down / 1000) diff --git a/v2rayN/ServiceLib/Services/Statistics/StatisticsXrayService.cs b/v2rayN/ServiceLib/Services/Statistics/StatisticsXrayService.cs index d09ae836..b64a515d 100644 --- a/v2rayN/ServiceLib/Services/Statistics/StatisticsXrayService.cs +++ b/v2rayN/ServiceLib/Services/Statistics/StatisticsXrayService.cs @@ -6,10 +6,10 @@ public class StatisticsXrayService private ServerSpeedItem _serverSpeedItem = new(); private readonly Config _config; private bool _exitFlag; - private Action? _updateFunc; + private readonly Func? _updateFunc; private string Url => $"{Global.HttpProtocol}{Global.Loopback}:{AppManager.Instance.StatePort}/debug/vars"; - public StatisticsXrayService(Config config, Action updateFunc) + public StatisticsXrayService(Config config, Func updateFunc) { _config = config; _updateFunc = updateFunc; @@ -39,7 +39,7 @@ public class StatisticsXrayService if (result != null) { var server = ParseOutput(result) ?? new ServerSpeedItem(); - _updateFunc?.Invoke(server); + await _updateFunc?.Invoke(server); } } catch diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index b3a66892..0149c0fb 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -373,14 +373,14 @@ public class ClashProxiesViewModel : MyReactiveObject private async Task ProxiesDelayTest(bool blAll = true) { - ClashApiManager.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), (item, result) => + ClashApiManager.Instance.ClashProxiesDelayTest(blAll, _proxyDetails.ToList(), async (item, result) => { if (item == null || result.IsNullOrEmpty()) { return; } - _updateView?.Invoke(EViewAction.DispatcherProxiesDelayTest, new SpeedTestResult() { IndexId = item.Name, Delay = result }); + await _updateView?.Invoke(EViewAction.DispatcherProxiesDelayTest, new SpeedTestResult() { IndexId = item.Name, Delay = result }); }); await Task.CompletedTask; } diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 7f5d53a4..eab61655 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -272,13 +272,13 @@ public class MainWindowViewModel : MyReactiveObject } } - private void UpdateStatisticsHandler(ServerSpeedItem update) + private async Task UpdateStatisticsHandler(ServerSpeedItem update) { if (!_config.UiItem.ShowInTaskbar) { return; } - _updateView?.Invoke(EViewAction.DispatcherStatistics, update); + await _updateView?.Invoke(EViewAction.DispatcherStatistics, update); } public void SetStatisticsResult(ServerSpeedItem update)