473,324 Members | 2,541 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.

Is this a bug in .net file io? is there a work around?

Is this a bug in .net file io? is there a work around?

when writing a large file with using(StreamWriter ... if the network drive
of the share is removed then the file is never closed. I tried doing the
using clause, i tried both close and closehandle in the finaly clause. in
all cases if a large file is being written to a network drive and the
network drive is disconnected the file handle remains open. when i try to
close, dispose, or closehandle it in the finaly clause it fails to close
because it tries to flush the buffer in all of those cases. is this a bug in
..net file io? is there a work around? do i need to write a dll in c that
does file io to get around this? is there a workaround in .net? i also tried
unlocking the file stream in the finaly clause and it still keeps the file
open. is there any way tof orce a filestream to close a file without trying
to flush the buffer in .net?

here is the test case, i put break points in all the catch and finally
clauses. in all cases i am unable to close the file when it throws error
because i disconnect the network drive while it is in the middle of writing
out the file.

using System;
using System.Runtime.InteropServices;

namespace cleanclose
{
class Class1
{

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
static void Main(string[] args)
{
string strTempPath = @"\\123.123.123.123\netdistest\mb30file.txt";
System.Text.StringBuilder sb = new System.Text.StringBuilder(100000000);
for(int i=0;i<100000000;i++)
{
sb.Append("0");
}
string request = sb.ToString();
System.IntPtr lasthandle = new System.IntPtr(-1);
while(true)
{
System.IO.FileStream fs = null;
System.IO.StreamWriter fr = null;
try
{
fs=new System.IO.FileStream(strTempPath, System.IO.FileMode.Create);
fr=new System.IO.StreamWriter(fs, System.Text.Encoding.UTF8);
lasthandle = fs.Handle;
}
catch
{
try
{
CloseHandle(lasthandle);
}
catch(Exception eech)
{
int i234222 = 23 + 23;
}

}
try
{
fr.Write(request);
}
catch(Exception ee1)
{
int i23 = 23 + 23;
}
finally
{
try
{
fr.Close();
}
catch(Exception ee2)
{
try
{
fs.Close();
}
catch(Exception ee3)
{
try
{
CloseHandle(fs.Handle);
}
catch(Exception ee4)
{
try
{
fs.Unlock(0, fs.Length);
}
catch
{
int isdfw = 23 + 23;
}
}
}
}
}
}
}
}
}
Nov 12 '05 #1
0 951

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

Similar topics

5
by: Gregg | last post by:
Hello all, I have been banging my head over a problem that I am having reading a comma seperated file (CSV) that can contain from 1 to 10,000 records. My code snipit is as follows: **Start...
0
by: Daniel | last post by:
Is this a bug in .net file io? is there a work around? when writing a large file with using(StreamWriter ... if the network drive of the share is removed then the file is never closed. I tried...
2
by: Ted Duross | last post by:
Hi, I’ve created an educational software application accessed by students from a central server. On Start-Up the application reads an XML file that stores student progress records. This XML...
14
by: Stingray | last post by:
I think this is more of a general IE/HTTP question but I didn't know where to post. If this is not the place for it, please point me to the right group. Thanks. Here's my question: I have an...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
15
by: Bryan | last post by:
Hello all, In some html code I have the following: <script type='text/javascript' src='foo.js'></script> However, I'd like to replace 'foo.js' with something like "bar.php?file=foo" and...
1
by: ujjwaltrivedi | last post by:
Hey guys, Can anyone tell me how to create a text file with Unicode Encoding. In am using FileStream Finalfile = new FileStream("finalfile.txt", FileMode.Append, FileAccess.Write); ...
1
by: TYR | last post by:
I have a large dump file that originated in a MySQL db; I need to get it into an SQLite file. Various options are suggested around the web; none of them seem to work (most failing to import the...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.