System.ObjectDisposedException:无法访问关闭的Stream [英] System.ObjectDisposedException: Cannot access a closed Stream

查看:115
本文介绍了System.ObjectDisposedException:无法访问关闭的Stream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是真的,这不一定意味着该流已通过代码进行了处置-在使用中或通过调用dispose进行.

Is it true that this does not necessarily mean the stream has been disposed of by code - either in a using or by calling dispose.

该流可能已在此代码之外关闭,并且仍然会发生此异常?

The stream could have been closed outside of this code and this exception would still occur?

推荐答案

所以我将在评论中回答:是的,从您的代码外部也可以关闭流,因此请确保检查 System.ObjectDisposedException .

So I will make my comment an answer: Yes, a stream could just as well be closed from outside your code, so make sure you check for a System.ObjectDisposedException.

在几种情况下可能会发生这种情况:例如,想象与网络连接关联的流并且该连接突然中断.根据实现的不同,这可能会关闭流并在访问该流时抛出该特定异常.

There are several occasions this could happen: imagine for example a stream associated with a network connection and the connection is suddenly interrupted. Depending on the implementation this could close the stream and throw that particular exception if the stream is accessed.

这篇关于System.ObjectDisposedException:无法访问关闭的Stream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆