From 1548e0d4ac0890052004f3c81b6ca763b0021b0f Mon Sep 17 00:00:00 2001 From: Adam Simon Date: Wed, 31 Jul 2024 09:37:18 +0200 Subject: [PATCH] Fix sonar issues --- .../ConfigService/DefaultConfigFetcher.cs | 7 ++++++- src/ConfigCatClient/Override/LocalFileDataSource.cs | 12 ++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ConfigCatClient/ConfigService/DefaultConfigFetcher.cs b/src/ConfigCatClient/ConfigService/DefaultConfigFetcher.cs index de2c8b11..d25f1432 100644 --- a/src/ConfigCatClient/ConfigService/DefaultConfigFetcher.cs +++ b/src/ConfigCatClient/ConfigService/DefaultConfigFetcher.cs @@ -223,7 +223,12 @@ private static Uri ReplaceUri(Uri oldUri, Uri newUri) public void Dispose() { - this.cancellationTokenSource.Cancel(); + if (!this.cancellationTokenSource.IsCancellationRequested) + { + try { this.cancellationTokenSource.Cancel(); } + catch (ObjectDisposedException) { /* intentional no-op */ } + } + this.cancellationTokenSource.Dispose(); this.configFetcher.Dispose(); } diff --git a/src/ConfigCatClient/Override/LocalFileDataSource.cs b/src/ConfigCatClient/Override/LocalFileDataSource.cs index f48351c3..abe7047f 100644 --- a/src/ConfigCatClient/Override/LocalFileDataSource.cs +++ b/src/ConfigCatClient/Override/LocalFileDataSource.cs @@ -145,15 +145,15 @@ private async Task ReloadFileAsync(bool isAsync, CancellationToken cancellationT this.fileLastWriteTime = File.GetLastWriteTimeUtc(this.fullPath); } - internal void StopWatch() - { - this.cancellationTokenSource.Cancel(); - } - public void Dispose() { // Background work should stop under all circumstances - this.cancellationTokenSource.Cancel(); + if (!this.cancellationTokenSource.IsCancellationRequested) + { + try { this.cancellationTokenSource.Cancel(); } + catch (ObjectDisposedException) { /* intentional no-op */ } + } + this.cancellationTokenSource.Dispose(); } internal sealed class SimplifiedConfig