Fix PeriodicBackgroundWorker

This commit is contained in:
ngfrolov 2023-11-28 16:31:31 +05:00
parent 399dab884f
commit dd99497e75
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -17,8 +17,8 @@ public class PeriodicBackgroundWorker : BackgroundService
private readonly TimeSpan executePeriod = TimeSpan.FromSeconds(10);
private readonly TimeSpan minDelay = TimeSpan.FromSeconds(1);
private readonly IServiceProvider serviceProvider;
private readonly List<WorkPeriodic> works = new(8);
private bool isRuning = false;
/// <summary>
/// Список периодических работ
@ -42,6 +42,9 @@ public class PeriodicBackgroundWorker : BackgroundService
protected override async Task ExecuteAsync(CancellationToken token)
{
if (isRuning)
return;
isRuning = true;
Trace.TraceInformation($"{GetType().Name} started");
while (!token.IsCancellationRequested)
{
@ -74,6 +77,7 @@ public class PeriodicBackgroundWorker : BackgroundService
Trace.TraceError(MainLoopLastException);
}
}
isRuning = false;
}
/// <summary>