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.
"Pascal Schmitt" <ne*******@cebra.nu> wrote in message
news:en****************@TK2MSFTNGP12.phx.gbl...
Daniel wrote: if System.IO.StreamWriter write throws an exception, is there anyway to
close the System.IO.StreamWriter object? it seems to stay open when this
happens then future attempts to write to that same path fail because it
says its in use by another process.
The finally-block has been invented for this (untested):
StreamWriter w;
try {
w = new StreamWriter(null);
// 1. an exception is thrown
}
catch {
Debug.WriteLine("!");
// 2. you handle it
}
finally {
/* 3. you clean up behind you, no matter if the exception was thrown
or not! */
if( w != null ){
w.Close();
w = null;
}
}
--
Pascal Schmitt