How do I know if a stream is closed?

I have a method with a stream for input:

public void Export(Stream finalOutPutStream) 

For testing purposes, I call it with a memory stream, for example:

 // When _exporter.Export(new System.IO.MemoryStream()); 

But when in the method that I want to write to this memory stream, I get an ObjectDisposedException.

This thread is not wrapped in a using statement; I do not explicitly call .Dispose ().

What happened?

Thanks:)

- EDIT: my bad, the problem is with a third-party author ( DotNetZip ). An exception occurs when I call zip.Save (new MemoryStream ()). I will ask my questions on their forum. Sorry, thanks for the help.

+6
source share
2 answers

You can check the availability of the stream using the following properties: CanRead , CanSeek , CanWrite .

+4
source

if you create a stream creation inside, it will do for you closing and releasing EX resources:

 using(Stream s = new MemoryStream()) { // do your operations } 
-6
source

Source: https://habr.com/ru/post/896110/


All Articles