diff --git a/Endpoint/Controllers/V1/Configuration/ScheduleController.cs b/Endpoint/Controllers/V1/Configuration/ScheduleController.cs index 6191c6d..f965040 100644 --- a/Endpoint/Controllers/V1/Configuration/ScheduleController.cs +++ b/Endpoint/Controllers/V1/Configuration/ScheduleController.cs @@ -199,13 +199,20 @@ public class ScheduleController(ILogger logger, IOptionsSnap } var scopeFactory = provider.GetRequiredService(); - _ = Task.Run(async () => + ThreadPool.QueueUserWorkItem(async void (_) => { + try + { using var scope = scopeFactory.CreateScope(); - var sync = scope.ServiceProvider.GetRequiredService(); + var sync = (ScheduleSynchronizer)ActivatorUtilities.GetServiceOrCreateInstance(scope.ServiceProvider, typeof(ScheduleSynchronizer)); await sync.StartSync(filePaths, CancellationToken.None); - }, CancellationToken.None); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + }); return Ok(); }