The thread could be closed outside of this code, and this exception will happen anyway?
Yes. For example, this can happen if you exchange a stream in another stream and delete the wrapper stream. Many implementations have a thread that they wrap.
If you then try to write to a wrapped stream, you will receive this error message.
either when using or when calling dispose.
Also, be aware that for objects that have a Close()
method, such as Stream
, Close
and Dispose
, they usually perform the same function. Closing a thread also eliminates this.
source share