From 717dfcd9239a0815b53e999f28bed1a1b7b1509d Mon Sep 17 00:00:00 2001 From: MBucari Date: Tue, 11 Nov 2025 14:06:54 -0700 Subject: [PATCH] Fix trying to cancel disposed cancellation token source --- Source/AaxDecrypter/NetworkFileStream.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/AaxDecrypter/NetworkFileStream.cs b/Source/AaxDecrypter/NetworkFileStream.cs index 769a76fc..ae9d961a 100644 --- a/Source/AaxDecrypter/NetworkFileStream.cs +++ b/Source/AaxDecrypter/NetworkFileStream.cs @@ -306,7 +306,7 @@ namespace AaxDecrypter if (WritePosition > endPosition) throw new WebException($"Downloaded size (0x{WritePosition:X10}) is greater than {nameof(ContentLength)} (0x{ContentLength:X10})."); } - catch (TaskCanceledException) + catch (OperationCanceledException) { Serilog.Log.Information("Download was cancelled"); } @@ -402,7 +402,7 @@ namespace AaxDecrypter */ protected override void Dispose(bool disposing) { - if (disposing && !disposed) + if (disposing && !Interlocked.CompareExchange(ref disposed, true, false)) { _cancellationSource.Cancel(); DownloadTask?.GetAwaiter().GetResult(); @@ -413,7 +413,6 @@ namespace AaxDecrypter OnUpdate(waitForWrite: true); } - disposed = true; base.Dispose(disposing); }