System.ObjectDisposedException: Unable to access private thread

Is it true that this does not necessarily mean that the stream was deleted by the code - either in use or when calling dispose.

The thread could be closed outside of this code, and this exception will happen anyway?

+6
source share
3 answers

So, I will make my comment the answer: Yes, the thread can also be closed outside of your code, so make sure that you System.ObjectDisposedException .

This can happen several times: imagine, for example, a stream connected to a network connection, and the connection aborts abruptly. Depending on the implementation, this may close the stream and pass this particular exception if the stream is accessed.

+6
source

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.

+2
source

This error can also occur if requestLengthDiskThreshold is less than the size of the file you are trying to load / process through the stream. This is defined in your web.config:

 <httpRuntime maxRequestLength="512000" requestLengthDiskThreshold="512000" /> 

If you read the explanation for the second parameter here:

https://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.requestlengthdiskthreshold(v=vs.110).aspx

you will see that it sets the input-stream buffering threshold (in kilobytes). The default value is 80 KB, so if you do not have this value and you are trying, for example, to load an ajax file larger than 80 KB, you will get a System.ObjectDisposedException exception, because the stream will be closed after reaching the threshold limit.

In my case, I set the threshold to 500 MB ...

0
source

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


All Articles