Fix bot things
This commit is contained in:
@@ -31,25 +31,36 @@ namespace Managing.Domain.Bots
|
||||
|
||||
public async Task InitWorker(Func<Task> action)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
while (Status == BotStatus.Up)
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
while (Status == BotStatus.Up && !CancellationToken.IsCancellationRequested)
|
||||
{
|
||||
await action();
|
||||
try
|
||||
{
|
||||
await action();
|
||||
ExecutionCount++;
|
||||
await Task.Delay(Interval, CancellationToken.Token);
|
||||
if (CancellationToken.IsCancellationRequested)
|
||||
break;
|
||||
}
|
||||
catch (TaskCanceledException) when (CancellationToken.IsCancellationRequested)
|
||||
{
|
||||
// Graceful shutdown when cancellation is requested
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
ExecutionCount++;
|
||||
await Task.Delay(Interval, CancellationToken.Token);
|
||||
if (CancellationToken.IsCancellationRequested)
|
||||
break;
|
||||
}
|
||||
}, CancellationToken.Token);
|
||||
}, CancellationToken.Token);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
|
||||
Reference in New Issue
Block a user