From ff654a3b4a9326f9a559d8572ebe98d56f6202c8 Mon Sep 17 00:00:00 2001 From: Omar Boukli-Hacene Date: Tue, 21 Nov 2023 22:10:17 +0200 Subject: [PATCH] fix: Dispose CancellationTokenSource --- .../HealthCheckBackgroundService.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Aktabook.Diagnostics.HealthChecks/HealthCheckBackgroundService.cs b/src/Aktabook.Diagnostics.HealthChecks/HealthCheckBackgroundService.cs index 5763854..7925cdf 100644 --- a/src/Aktabook.Diagnostics.HealthChecks/HealthCheckBackgroundService.cs +++ b/src/Aktabook.Diagnostics.HealthChecks/HealthCheckBackgroundService.cs @@ -37,6 +37,21 @@ public HealthCheckBackgroundService( new Thread(new ThreadStart(MakeStartDelegate(livenessListener))) { IsBackground = true }; } + private void Dispose(bool disposing) + { + if (disposing) + { + _listenerStoppingTokenSource.Dispose(); + } + } + + public override void Dispose() + { + Dispose(true); + base.Dispose(); + GC.SuppressFinalize(this); + } + protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await Task.Yield();