mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-18 03:05:00 +03:00
Optimizing Task Code
This commit is contained in:
@@ -53,26 +53,31 @@ namespace ServiceLib.ViewModels
|
||||
|
||||
private async Task Init()
|
||||
{
|
||||
var lastTime = DateTime.Now;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var numOfExecuted = 1;
|
||||
while (true)
|
||||
{
|
||||
await Task.Delay(1000 * 5);
|
||||
numOfExecuted++;
|
||||
if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_config.ClashUIItem.ConnectionsRefreshInterval <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (numOfExecuted % _config.ClashUIItem.ConnectionsRefreshInterval != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
await GetClashConnections();
|
||||
}
|
||||
});
|
||||
|
||||
Observable.Interval(TimeSpan.FromSeconds(5))
|
||||
.Subscribe(async x =>
|
||||
{
|
||||
if (!(AutoRefresh && _config.UiItem.ShowInTaskbar && _config.IsRunningCore(ECoreType.sing_box)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var dtNow = DateTime.Now;
|
||||
if (_config.ClashUIItem.ConnectionsRefreshInterval > 0)
|
||||
{
|
||||
if ((dtNow - lastTime).Minutes % _config.ClashUIItem.ConnectionsRefreshInterval == 0)
|
||||
{
|
||||
await GetClashConnections();
|
||||
lastTime = dtNow;
|
||||
}
|
||||
Task.Delay(1000).Wait();
|
||||
}
|
||||
});
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user