The reason you can't close the file is because Close() tries to flush the
stream which fails as you've lost the connection with the remote resource.
One possibility to recover from this, is to use the FileStream class and
call Win32 API CloseHandle when such exception occurs, doing so will release
the OS file handle so you can re-open the file.
[ DllImport("Kernel32") ]
public static extern bool CloseHandle(IntPtr handle);
....
FileStream fs;
try {
...
}
catch(IOException)
{
// If resource no longer available, or unable to write to.....
if(...)
CloseHandle(fs.Handle);
}
Willy.
PS. Please be patient, don't post the same question over and over again and
don't multipost.
"Daniel" <so*******************@yahoo.com> wrote in message
news:uW**************@TK2MSFTNGP10.phx.gbl...
If my System.IO.StreamWriter Write method throws "The specified network
name
is no longer available." and I try to Dispose or Close it in the finaly
clause the close or dispose method just throws "The specified network name
is no longer available." again. how to clean this up? after this the
stream
writer is stuck connected until i restart my process.