开发者

How can you know if a stream is closed? [closed]

开发者 https://www.devze.com 2023-03-31 16:20 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally appl开
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally appl开发者_StackOverflow社区icable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I have a method with a Stream for input :

public void Export(Stream finalOutPutStream)

For test purposes, i call it with a memory stream, like this :

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

But when, in the method, i want to write on this memory stream, i get a ObjectDisposedException.

This stream is not enclosed in a using statement, i do not call explicitely .Dispose().

What happened ?

Thanks :)

-- EDIT : my bad, the problem is from the third party writer (DotNetZip). The exception happens when i call zip.Save(new MemoryStream()). I will ask my questions on their forum. Sorry, and thanks for the help.


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


if you put the stream creation inside using it will do the closing and resource release for you EX:

using(Stream s = new MemoryStream())
{
 // do your operations
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号