473,466 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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;
}
}
}
}
}
}
}
}
}
Sep 28 '05 #1
0 1280

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...
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...
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...
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.