diff --git a/Source/AaxDecrypter/NetworkFileStream.cs b/Source/AaxDecrypter/NetworkFileStream.cs index 183fff7e..eaab46f1 100644 --- a/Source/AaxDecrypter/NetworkFileStream.cs +++ b/Source/AaxDecrypter/NetworkFileStream.cs @@ -261,7 +261,6 @@ namespace AaxDecrypter catch (Exception ex) { Serilog.Log.Error(ex, "An error was encountered while downloading {Uri}", Uri); - IsCancelled = true; } finally { @@ -414,7 +413,7 @@ namespace AaxDecrypter var toRead = Math.Min(count, Length - Position); WaitToPosition(Position + toRead); - return IsCancelled ? 0 : _readFile.Read(buffer, offset, count); + return _readFile.Read(buffer, offset, count); } public override long Seek(long offset, SeekOrigin origin) @@ -436,14 +435,18 @@ namespace AaxDecrypter /// The minimum required flished data length in . private void WaitToPosition(long requiredPosition) { - while (requiredPosition > WritePosition && !IsCancelled && hasBegunDownloading && !downloadedPiece.WaitOne(1000)) ; + while (requiredPosition > WritePosition + && hasBegunDownloading + && !IsCancelled + && !downloadEnded.WaitOne(0) + && !downloadedPiece.WaitOne(100)) ; } public override void Close() { IsCancelled = true; - while (downloadEnded is not null && !downloadEnded.WaitOne(1000)) ; + while (downloadEnded is not null && !downloadEnded.WaitOne(100)) ; _readFile.Close(); _writeFile.Close();