Hello,
I've asked this before, but I never got a _good_ answer, so here's another
shot:
- Networks are unreliable, and servers cannot be guaranteed to have 100%
uptime.
After opening a file located on network drive (using FileStream and
exclusive locking), the network suddenly dies. The file is still locked by
the process, but cannot be reopened or closed.
// please enable your connection and open the file
FileStream fs1 = new FileStream(networkFile, FileMode.CreateNew,
FileAccess.Write, FileShare.Read);
// now, terminate your connection and do the following to fill the
FileStream buffers - this will ofcourse fail - BUT BUFFERS WILL BE FILLED
try {
byte[] ba = Encoding.Default.GetBytes("Hello World");
fs1.Write(ba, 0, ba.Length);
fs1.Flush();
} catch (Exception) { }
// now, enable your connection again (or don't), and try to close the file
// this will also fail since .Close() tries to flush buffers - resulting in
a file that can't be closed!!!
fs1.Close();
Does anyone got a solution for this specific problem? The file can't be
closed/disposed, the handle is still there, and it can't be reopened because
of the locking. Is there a way to _safely_ close the file - and release
possible handles?
Best Regards,
Fredrik Johansson