RE: Bug in FileStream.Dispose in Framework 1.1

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi

We have confirmed this is problem in our product, and we will plan to fix
it in the next release(Whidbey).

So you may try to use CloseHandle API to force the file handle release if
you found there is a IOException with error(disk is full)
This is just test code, you may adjust according or your scenario.
NOTE: Please try to get the FileHandle before the exception may occur.
class Class1
{
[DllImport("kernel32.dll")]
private static extern bool CloseHandle(IntPtr hObject);

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string path = @"..\..\Test1.txt";
string str = "Test";
byte[] bts = Encoding.ASCII.GetBytes(str);
//byte[] bts = new byte[512*1024*1024];
MessageBox.Show("Before Create");
FileStream fs = new FileStream(path,FileMode.OpenOrCreate);
IntPtr hFile = fs.Handle;
try
{
MessageBox.Show("Created");
while(true)
fs.Write(bts,0,bts.Length);
fs.Flush();
MessageBox.Show("Before Closed");
fs.Close();
MessageBox.Show("Closed");
}
catch(Exception ex)
{
try
{
MessageBox.Show(ex.ToString());
fs.Flush();
MessageBox.Show("Before Closed");
fs.Close();
MessageBox.Show("Closed");
}
catch(Exception exp)
{
try
{
MessageBox.Show(exp.ToString());
MessageBox.Show("Before Closed");
fs.Close();
MessageBox.Show("Closed");
}
catch(Exception expt)
{
MessageBox.Show(expt.ToString());
}
}
}
MessageBox.Show("Before Exit");
//MessageBox.Show(CloseHandle(hFile).ToString());//We have to call the
API to force close the file handle
fs = null;
MessageBox.Show("Before GC");
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
MessageBox.Show("After GC");
}
}


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages

  • Re: Testing Internet and Telephony Applications
    ... I need to prepare the test plan, schedule it, (reschedule in due ... going to take to report the problem. ... if there will be a fix. ... estimate testing time; your development manager or project manager has ...
    (comp.software.testing)
  • Re: Is Saudi Arabia Running Out of Oil?
    ... In the absence of a quick fix or a painless fix and in the ... individuals to plan accordingly in terms of business strategy, ... newsgroup plan to do, if anything. ...
    (sci.energy)
  • Re: Obama Prize Patrol
    ... " Obama Prize Patrol ... Barrack Obama announced the other day he has a plan to fix our ... ...for the low low price of 18 Billion dollars. ... dollars every month in Iraq and lets fix all these problems - dimwit. ...
    (alt.politics.bush)
  • Re: Frozen pipe question
    ... So now we're at Plan B, which is "fix it ourselves". ... same plumber fix the same pipe, for the same reason, and undoubtedly more ... thing call a frost free valve (faucet) for hose outlets. ...
    (alt.home.repair)
  • Re: [discuss] Re: Please pull x86-64 bug fixes
    ... Oh so you plan to fix the iommu/aacraid problem you always said you ... Actually I plan to fix this one, but it will require more work. ... Basically the plan is to make the current dma zone variable sized ... and get rid of all GFP_DMA allocations. ...
    (Linux-Kernel)