diff --git a/src/DotNext.IO/IO/SparseStream.cs b/src/DotNext.IO/IO/SparseStream.cs index f2c3a9f81..64bf53632 100644 --- a/src/DotNext.IO/IO/SparseStream.cs +++ b/src/DotNext.IO/IO/SparseStream.cs @@ -188,9 +188,12 @@ protected override void Dispose(bool disposing) public override async ValueTask DisposeAsync() { - for (var i = 0; i < Streams.Length; i++) + if (!leaveOpen) { - await Streams[i].DisposeAsync().ConfigureAwait(false); + for (var i = 0; i < Streams.Length; i++) + { + await Streams[i].DisposeAsync().ConfigureAwait(false); + } } GC.SuppressFinalize(this);