C# .NET - Close or dispose stream objects in a loop

Asked By Pranay on 04-Apr-13 12:55 PM
I've a loop where in I 've to  ftp files. Is it a good idea to dispose the stream object for every single run of the loop or I should just close it after every run and use Dispose after I'm done with all the runs of the loop.  Although, I think I should only dispose after the final run of the loop but I'm not very sure.

Thanks
Robbe Morris replied to Pranay on 04-Apr-13 01:09 PM
After each file.
Pranay replied to Robbe Morris on 04-Apr-13 02:00 PM
Hi Robbe,
Thanks a lot for your help. I know you are the admin of this website, that's why I wanted to bring this to your notice. I was wondering if we could get a reply option to our own posts. Sometimes, I find answer to my posts even before someone replies and in some cases they are left unanswered. If I had option of replying to my own post I would put up the solution which might help other guys in future.
Robbe Morris replied to Pranay on 04-Apr-13 02:24 PM
Well, we used to have some options like this while our forum contest was running but guys were using it to gain fraudulent points.  I could probably open this to the top post in the thread.  I'll see if I can get some time to do that.

As for your original question, you typically want to close out anything that implements IDisposable (streams for instance) as soon as possible to release the resource.