From 5effbee50bb1fc17cb45114bcf37e57db8958640 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:41:01 +0800 Subject: [PATCH] Fix https://github.com/2dust/v2rayN/issues/5905 --- v2rayN/ServiceLib/Handler/AppHandler.cs | 2 +- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 2 +- v2rayN/ServiceLib/Handler/ProfileExHandler.cs | 14 +++++++++----- .../ServiceLib/ViewModels/MainWindowViewModel.cs | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/AppHandler.cs b/v2rayN/ServiceLib/Handler/AppHandler.cs index c5b43850..e27634fa 100644 --- a/v2rayN/ServiceLib/Handler/AppHandler.cs +++ b/v2rayN/ServiceLib/Handler/AppHandler.cs @@ -159,7 +159,7 @@ await ConfigHandler.SetDefaultServer(_config, lstModel); var lstServerStat = (_config.GuiItem.EnableStatistics ? StatisticsHandler.Instance.ServerStat : null) ?? []; - var lstProfileExs = ProfileExHandler.Instance.ProfileExs; + var lstProfileExs = await ProfileExHandler.Instance.GetProfileExs(); lstModel = (from t in lstModel join t2 in lstServerStat on t.IndexId equals t2.IndexId into t2b from t22 in t2b.DefaultIfEmpty() diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index ef0cdfae..baf50c29 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -746,7 +746,7 @@ namespace ServiceLib.Handler { return -1; } - var lstProfileExs = ProfileExHandler.Instance.ProfileExs; + var lstProfileExs = await ProfileExHandler.Instance.GetProfileExs(); var lstProfile = (from t in lstModel join t3 in lstProfileExs on t.IndexId equals t3.IndexId into t3b from t33 in t3b.DefaultIfEmpty() diff --git a/v2rayN/ServiceLib/Handler/ProfileExHandler.cs b/v2rayN/ServiceLib/Handler/ProfileExHandler.cs index 3d52f930..1eee7558 100644 --- a/v2rayN/ServiceLib/Handler/ProfileExHandler.cs +++ b/v2rayN/ServiceLib/Handler/ProfileExHandler.cs @@ -9,27 +9,31 @@ namespace ServiceLib.Handler private static readonly Lazy _instance = new(() => new()); private ConcurrentBag _lstProfileEx = []; private Queue _queIndexIds = new(); - public ConcurrentBag ProfileExs => _lstProfileEx; public static ProfileExHandler Instance => _instance.Value; public ProfileExHandler() { - Init(); + //Init(); } - private async Task Init() + public async Task Init() { await InitData(); - await Task.Run(async () => + Task.Run(async () => { while (true) { - await SaveQueueIndexIds(); await Task.Delay(1000 * 600); + await SaveQueueIndexIds(); } }); } + public async Task> GetProfileExs() + { + return _lstProfileEx; + } + private async Task InitData() { await SQLiteHelper.Instance.ExecuteAsync($"delete from ProfileExItem where indexId not in ( select indexId from ProfileItem )"); diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 1352b987..b75cda3d 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -208,6 +208,7 @@ namespace ServiceLib.ViewModels await ConfigHandler.InitBuiltinRouting(_config); await ConfigHandler.InitBuiltinDNS(_config); + await ProfileExHandler.Instance.Init(); await CoreHandler.Instance.Init(_config, UpdateHandler); TaskHandler.Instance.RegUpdateTask(_config, UpdateTaskHandler);