How to stop GzipStream blocking in Dispose?

99 views Asked by At

I am reading from a GzipStream which wraps a NetworkStream in a UI event handler.

using (var gzipStream = new GzipStream(networkStream, CompressionMode.Decompress) {
    await WriteSomethingToStream(gzipStream);
}

The DeflateStream which the GzipStream wraps has a blocking Write call in it's Dispose method for flushing the buffer.
So at the end of Using statement, gzipStream.Dispose() blocks, and UI will block.

There is no GzipStream.DisposeAsync/CloseAsync() method either.

So how do I not block while disposing? FlushAsync doesn't work because according to it's(Flush) documentation, it does nothing.

The current implementation of this method does not flush the internal buffer. The internal buffer is flushed when the object is disposed.

0

There are 0 answers