473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 longe

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.
Nov 17 '05 #1
1 5484
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.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: python newbie | last post by:
Hi, I have a wxPython app which dump errors when I close it ( in the debug output at bottom of Komodo, when I close my app. ) Where I got the code for my GUI: Straight from the wxProject.py...
0
by: Alex Nordhus | last post by:
I need some help. I cant seem to get rid of this error. I can program a button that will exit the program and remove the icon in the taskbar, but I have to tie it to OnTaskBarClose. OnExit and...
3
by: Daniel | last post by:
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...
5
by: Stan | last post by:
When I create a Web project and then try to add the files to it (Add Existing Item), I get this error message "The folder http://localhost/FinWeb is no longer availabe" In fact the folder and...
4
by: whoopdaddy | last post by:
We are streaming a PDF file out of an ASPX page in IIS 5 using Response.WriteFile so the user does not need permissions to the directory where the files are stored. This works great when the user is...
10
by: newbie | last post by:
My application_end event in global.asax is not working as-is. In order to debug, I want to call it from another file, say debug.aspx through a button, e.g. "end application". How do I call...
5
by: engsolnorm | last post by:
I'm playing with a sudoku GUI...just to learn more about python. I've made 81 'cells'...actually small canvases Part of my scheme to write the cells (all 81 of them in the gui) to a file (using...
1
kaleeswaran
by: kaleeswaran | last post by:
hi! i want to get the system name from the network connected system. how to do that?... thank you, kaleeswaran
0
by: enggwaqas | last post by:
I am exposing my Biztalk orchestration as a web service and want to consume this web service asyncly, but when i added web reference in my visual studio project it isn't displying Begin<Web Method...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.