From ea4c8b61e083ce791578e511339b11f6a9154f76 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Mon, 3 Feb 2025 11:25:39 +0300 Subject: [PATCH] refactor: use thread pool instead task --- .../V1/Configuration/ScheduleController.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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(); }