From 0a1c864c4e14fd04451e4cbdb4f4cc8873cb3c2a Mon Sep 17 00:00:00 2001 From: MaksimChegulov Date: Thu, 10 Feb 2022 18:10:43 +0300 Subject: [PATCH] ClearEvents: fix dispose --- .../ASC.ClearEvents/Services/ClearEventsService.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/services/ASC.ClearEvents/Services/ClearEventsService.cs b/common/services/ASC.ClearEvents/Services/ClearEventsService.cs index 467f750579..91db22cfbd 100644 --- a/common/services/ASC.ClearEvents/Services/ClearEventsService.cs +++ b/common/services/ASC.ClearEvents/Services/ClearEventsService.cs @@ -30,7 +30,7 @@ public class ClearEventsService : IHostedService, IDisposable { private readonly ILog _logger; private readonly IServiceScopeFactory _serviceScopeFactory; - private Timer _timer = null!; + private Timer _timer; public ClearEventsService(IOptionsMonitor options, IServiceScopeFactory serviceScopeFactory) { @@ -59,9 +59,14 @@ public class ClearEventsService : IHostedService, IDisposable public void Dispose() { + if (_timer == null) + { + return; + } + var handle = new AutoResetEvent(false); - if ((bool)!(_timer?.Dispose(handle))) + if (!_timer.Dispose(handle)) { throw new Exception("Timer already disposed"); }