473,386 Members | 1,785 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,386 software developers and data experts.

Leaking SafeFileHandles

Hello,

I've asked this before, but I never got a _good_ answer, so here's another
shot:

- Networks are unreliable, and servers cannot be guaranteed to have 100%
uptime.

After opening a file located on network drive (using FileStream and
exclusive locking), the network suddenly dies. The file is still locked by
the process, but cannot be reopened or closed.

// please enable your connection and open the file
FileStream fs1 = new FileStream(networkFile, FileMode.CreateNew,
FileAccess.Write, FileShare.Read);

// now, terminate your connection and do the following to fill the
FileStream buffers - this will ofcourse fail - BUT BUFFERS WILL BE FILLED
try {
byte[] ba = Encoding.Default.GetBytes("Hello World");
fs1.Write(ba, 0, ba.Length);
fs1.Flush();
} catch (Exception) { }

// now, enable your connection again (or don't), and try to close the file
// this will also fail since .Close() tries to flush buffers - resulting in
a file that can't be closed!!!
fs1.Close();
Does anyone got a solution for this specific problem? The file can't be
closed/disposed, the handle is still there, and it can't be reopened because
of the locking. Is there a way to _safely_ close the file - and release
possible handles?
Best Regards,
Fredrik Johansson
Apr 25 '07 #1
0 990

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

Similar topics

1
by: David Ei | last post by:
I'm working on a C# Windows Forms application that is leaking memory. I've been using the SciTech NetMem Profiler 2 (A really great tool, BTW) to track down leaks. I've found one related to...
0
by: Frank Lopez | last post by:
My program structure is: 1. 2. 3. => manually does the crt-init and crt-terminate calls 4. -- this is accessed by the unmanaged C++ classes in (3) using LoadLibrary and FreeLibrary
1
by: Matt Gertz | last post by:
Phil, Thanks for the notification on this. I'm going to do some investigation on this today & try debugging through the problem, and I'll get back to you either this afternoon or tomorrow...
13
by: Rich B. | last post by:
I have an MDI form with a single child form. I have found a couple of circumstances that appear to cause the framework to leak Int32s, MenuItems, MenuItemCollections and sometimes...
6
by: Sigmathaar | last post by:
Hi, I'm having some trouble while debuging some code. My compiler says the code is OK but whenever I try to execute the program nothing happens. Using my debuger I got the next message : ...
7
by: Brano | last post by:
Hi all, I have a VB.NET Dll that is invoked via BizTalk 2002 AIC over Http protocol. the Dll is making a connection using a 3rd party connector to a Unidata database (old legacy stuff) All I...
5
by: Doug Wright | last post by:
Hi The code in question is available from http://mozilla.pastebin.com/596645 Any help would be extremly appreciated, because I've spent many hours on trying to figure this out!!
6
by: zl2k | last post by:
hi, When I considered about preventing memory leaking, the method came up to my mind is using boost smart pointer if possible (use stl::vector instead of type, use smart pointer whenever declare...
23
by: gNash | last post by:
#include <stdio.h> #include <string.h> #include <stdlib.h> char * strclear(const char *str) { char *string; string=(char *)malloc(strlen(str)+1); strcpy(string,str); return string;
3
by: rupert.thurner | last post by:
the edgewall trac release 0.11 is blocked now since more than one month for a memory leak nobody is able to find, see http://groups.google.com/group/trac-dev/browse_thread/thread/116e519da54f16b...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.