Code optimization, function asynchrony

This commit is contained in:
2dust
2024-10-22 17:50:42 +08:00
parent 3bf2dc711d
commit b3c2084b76
10 changed files with 28 additions and 31 deletions
@@ -14,9 +14,14 @@ namespace ServiceLib.Handler
public ProfileExHandler()
{
Init();
}
private async Task Init()
{
await InitData();
Task.Run(async () =>
{
await Init();
while (true)
{
await SaveQueueIndexIds();
@@ -25,7 +30,7 @@ namespace ServiceLib.Handler
});
}
private async Task Init()
private async Task InitData()
{
await SQLiteHelper.Instance.ExecuteAsync($"delete from ProfileExItem where indexId not in ( select indexId from ProfileItem )");
@@ -14,7 +14,7 @@
public List<ServerStatItem> ServerStat => _lstServerStat;
public void Init(Config config, Action<ServerSpeedItem> updateFunc)
public async Task Init(Config config, Action<ServerSpeedItem> updateFunc)
{
_config = config;
_updateFunc = updateFunc;
@@ -23,7 +23,7 @@
return;
}
InitData();
await InitData();
_statisticsV2Ray = new StatisticsV2rayService(config, UpdateServerStatHandler);
_statisticsSingbox = new StatisticsSingboxService(config, UpdateServerStatHandler);
-4
View File
@@ -5,10 +5,6 @@
private static readonly Lazy<TaskHandler> _instance = new(() => new());
public static TaskHandler Instance => _instance.Value;
public TaskHandler()
{
}
public void RegUpdateTask(Config config, Action<bool, string> updateFunc)
{
Task.Run(() => UpdateTaskRunSubscription(config, updateFunc));