Reputation: 2785
I am writing a web service that transfers a file over tcp using a binary, streaming connection.
I have some testing code set up but when I try to read the same file twice I get an exception, that the file is already open (by the previous call).
How can I close the file AFTER the transfer was complete? I tried a using block, but it didn't work.
Upvotes: 1
Views: 187
Reputation: 51349
It's covered here: http://devdump.wordpress.com/2008/12/07/disposing-return-values/
Furthermore, you probably want to open the streams using a constructor like this one, as follows:
var myStream = new FileStream("blah.txt", FileMode.Read, FileAccess.Read);
That way, multiple clients can call your method simultaneously.
Upvotes: 2