GDL <GD*@discussions.microsoft.com> wrote:
I'm using a FileStream as below:
FileStream fs = new FileStream
(
filePath,
FileMode.Create,
FileAccess.Write,
FileShare.None
);
//do some writing
fs.Write(...)
//close
fs.Close();
My problem is that even after the stream is closed no other applications can
access the file (resource in use) until I close the application which created
it.
Can anybody help with this please?
Given the code above, it's possible for an exception to occur and the
file handle not to be closed. A using statement would sort this:
using (FileStream fs = new FileStream (...))
{
// Do the writing
fs.Write (...);
// No need to manually close
}
If exceptions aren't occurring, that shouldn't be the problem, but the
above is better practice anyway.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too