From 7f12f48cb914ecbfb21fadb0388f31443c12fb78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Mon, 24 May 2021 16:30:35 +0500 Subject: [PATCH] fix backgroundService exception handler --- .../Services/BackgroundWorkerService.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs index 876d7635..e675db3a 100644 --- a/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs +++ b/AsbCloudInfrastructure/Services/BackgroundWorkerService.cs @@ -16,19 +16,19 @@ namespace AsbCloudInfrastructure.Services protected override async Task ExecuteAsync(CancellationToken token) { - try + while (!token.IsCancellationRequested) { - while (!token.IsCancellationRequested) + try { if (tasksQueue.TryDequeue(out var item)) - await Task.Run(()=>item.action(item.id), token); + await Task.Run(() => item.action(item.id), token); else await Task.Delay(100, token); } - } - catch - { - //logger ? + catch + { + //logger ? + } } }