replaced redundant CTS

This commit is contained in:
ThatBen 2025-04-04 08:31:27 +02:00
parent 3064445af9
commit d2a48e94cb
No known key found for this signature in database
GPG Key ID: E020A7DDCD52E1AB
2 changed files with 6 additions and 7 deletions

View File

@ -23,7 +23,7 @@ namespace AutoClient.Modes.FolderStore
status = statusFile.Load();
}
public void Run(CancellationTokenSource cts)
public void Run()
{
var folderFiles = Directory.GetFiles(app.Config.FolderToStore);
if (!folderFiles.Any()) throw new Exception("No files found in " + app.Config.FolderToStore);
@ -32,7 +32,7 @@ namespace AutoClient.Modes.FolderStore
balanceChecker.Check();
foreach (var folderFile in folderFiles)
{
if (cts.IsCancellationRequested) return;
if (app.Cts.IsCancellationRequested) return;
loadBalancer.CheckErrors();
if (!folderFile.ToLowerInvariant().EndsWith(FolderSaverFilename))
@ -43,7 +43,7 @@ namespace AutoClient.Modes.FolderStore
if (failureCount > 3)
{
app.Log.Error("Failure count reached threshold. Stopping...");
cts.Cancel();
app.Cts.Cancel();
return;
}

View File

@ -5,7 +5,6 @@ namespace AutoClient.Modes
public class FolderStoreMode
{
private readonly App app;
private readonly CancellationTokenSource cts = new CancellationTokenSource();
private Task checkTask = Task.CompletedTask;
private readonly LoadBalancer loadBalancer;
@ -22,9 +21,9 @@ namespace AutoClient.Modes
try
{
var saver = new FolderSaver(app, loadBalancer);
while (!cts.IsCancellationRequested)
while (!app.Cts.IsCancellationRequested)
{
saver.Run(cts);
saver.Run();
}
}
catch (Exception ex)
@ -37,7 +36,7 @@ namespace AutoClient.Modes
public void Stop()
{
cts.Cancel();
app.Cts.Cancel();
checkTask.Wait();
}
}