Recycling Streams in .NET ...

... is a bad idea.

Seems that either one or both of BinaryReader and StringReader dispose of the stream when the stream has been fully read. This can happen even when the Reader instance has not been disposed of!

So better to stick to the simple pattern of using streams as needed, and disposing of them immediately:

using ( Filestream fs = new Filestream ("@C:\myFile.txt") )
{
...
}

I guess this avoids making assumptions about how the Stream is implemented ...

Comments