Code optimization, function asynchrony

This commit is contained in:
2dust
2024-10-20 11:51:05 +08:00
parent 50449df08d
commit 394b657fc9
29 changed files with 467 additions and 526 deletions
+11 -12
View File
@@ -14,21 +14,20 @@ namespace ServiceLib.Handler
public ProfileExHandler()
{
Init();
Task.Run(async () =>
{
await Init();
while (true)
{
SaveQueueIndexIds();
await SaveQueueIndexIds();
await Task.Delay(1000 * 600);
}
});
}
private void Init()
private async Task Init()
{
SQLiteHelper.Instance.Execute($"delete from ProfileExItem where indexId not in ( select indexId from ProfileItem )");
await SQLiteHelper.Instance.ExecuteAsync($"delete from ProfileExItem where indexId not in ( select indexId from ProfileItem )");
_lstProfileEx = new(SQLiteHelper.Instance.Table<ProfileExItem>());
}
@@ -41,7 +40,7 @@ namespace ServiceLib.Handler
}
}
private void SaveQueueIndexIds()
private async Task SaveQueueIndexIds()
{
var cnt = _queIndexIds.Count;
if (cnt > 0)
@@ -72,10 +71,10 @@ namespace ServiceLib.Handler
try
{
if (lstInserts.Count() > 0)
SQLiteHelper.Instance.InsertAll(lstInserts);
await SQLiteHelper.Instance.InsertAllAsync(lstInserts);
if (lstUpdates.Count() > 0)
SQLiteHelper.Instance.UpdateAll(lstUpdates);
await SQLiteHelper.Instance.UpdateAllAsync(lstUpdates);
}
catch (Exception ex)
{
@@ -97,17 +96,17 @@ namespace ServiceLib.Handler
IndexIdEnqueue(indexId);
}
public void ClearAll()
public async Task ClearAll()
{
SQLiteHelper.Instance.Execute($"delete from ProfileExItem ");
await SQLiteHelper.Instance.ExecuteAsync($"delete from ProfileExItem ");
_lstProfileEx = new();
}
public void SaveTo()
public async Task SaveTo()
{
try
{
SaveQueueIndexIds();
await SaveQueueIndexIds();
}
catch (Exception ex)
{