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