473,763 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ 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(StreamWri ter ... 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("kern el32.dll", CharSet=CharSet .Auto)]
public extern static bool CloseHandle(Int Ptr handle);
static void Main(string[] args)
{
string strTempPath = @"\\123.123.123 .123\netdistest \mb30file.txt";
System.Text.Str ingBuilder sb = new System.Text.Str ingBuilder(1000 00000);
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.FileS tream fs = null;
System.IO.Strea mWriter fr = null;
try
{
fs=new System.IO.FileS tream(strTempPa th, System.IO.FileM ode.Create);
fr=new System.IO.Strea mWriter(fs, System.Text.Enc oding.UTF8);
lasthandle = fs.Handle;
}
catch
{
try
{
CloseHandle(las thandle);
}
catch(Exception eech)
{
int i234222 = 23 + 23;
}

}
try
{
fr.Write(reques t);
}
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 1315

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

Similar topics

5
2519
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 code snipit** Dim strCustFullName as string Dim strCustAddr1 as string
2
7467
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 file stores DataSet information, one DataTable and a number of DataRows, one per student. Once finished the student’s DataRow is updated and the DataSet is written to the XML file.
0
967
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 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...
14
3219
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 application that reads incoming email from a POP server and saves email messages as EML files, which OE can open and read. I'd like to save these files to a directory on a web server and create a web page that provides links to these files. When...
15
4778
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 button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is not validate based on some given rules. I also have a custom error handling page to show the...
1
6508
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" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
15
1638
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 have bar.php echo foo.js back to the script element. Is this possible?
1
3805
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 thing in the first place). So I removed the assorted taggery from each end, leaving just a big text file taking the following format: ('value', 'value', 'value, 'value'), ('value','value','value','value')...
185
7107
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 return the file name given a FILE *. Questions: What would be the best name for this function?
0
10149
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8825
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7370
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5271
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3918
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 we have to send another system
2
3529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2797
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.