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

OpenFileDialog Handle Leak

Hi there,

This is really crazy!

1. Make a folder
2. Put a text file in the folder
3. Run the following code...

Dim pop As New OpenFileDialog
Using pop
Call pop.ShowDialog()
End Using

4. Browse for the newly created text file
5. Press OK on the OpenFileDialog
6. Now try to delete the folder you created in step 1.

On my system I am being informed that a process is using the folder,
which it is, but why? The OpenFileDialog and SaveFileDialog automatically
instantiate a file handle to the folder when pressing OK? They dont make a
handle to the text file, only the folder...

Any ideas on how I can destroy this handle, I presumed disposing the
OpenFileDialog object would be adequate but obviously not as it should be
disposed by the 4th line.

Nick.
Jun 29 '06 #1
4 4001
BTW, the handle is released once the application is closed, so don't close
it until you have tried step 6.

"NickP" <a@a.com> wrote in message
news:uO**************@TK2MSFTNGP03.phx.gbl...
Hi there,

This is really crazy!

1. Make a folder
2. Put a text file in the folder
3. Run the following code...

Dim pop As New OpenFileDialog
Using pop
Call pop.ShowDialog()
End Using

4. Browse for the newly created text file
5. Press OK on the OpenFileDialog
6. Now try to delete the folder you created in step 1.

On my system I am being informed that a process is using the folder,
which it is, but why? The OpenFileDialog and SaveFileDialog automatically
instantiate a file handle to the folder when pressing OK? They dont make
a handle to the text file, only the folder...

Any ideas on how I can destroy this handle, I presumed disposing the
OpenFileDialog object would be adequate but obviously not as it should be
disposed by the 4th line.

Nick.

Jun 29 '06 #2
Hello NickP,
BTW, the handle is released once the application is closed, so don't
close it until you have tried step 6.


The problem here is the RestoreDirectory property. By default this is set
to false. By default calling ShowDialog() on OpenFileDialog will start in
the current directory for the process. If you change directories in the
dialog it will also change the current working directory of the process.
Unless you set RestoreDirectory process to True the last directory you enter
in the dialog will be the working directory of the process when you finish.
That's why you still have an open handle to the directory.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jun 29 '06 #3
Hi Jared,

Thanks for the info, so presumably I should be able to elliminate this
issue by changing the current working directory before attempting to delete
said folder? I'll have a try of that, many thanks and much appreciation :-)

Nick.

"Jared Parsons [MSFT]" <ja******@online.microsoft.com> wrote in message
news:61************************@msnews.microsoft.c om...
Hello NickP,
BTW, the handle is released once the application is closed, so don't
close it until you have tried step 6.


The problem here is the RestoreDirectory property. By default this is set
to false. By default calling ShowDialog() on OpenFileDialog will start in
the current directory for the process. If you change directories in the
dialog it will also change the current working directory of the process.
Unless you set RestoreDirectory process to True the last directory you
enter in the dialog will be the working directory of the process when you
finish. That's why you still have an open handle to the directory.
--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no
warranties, and confers no rights.

Jun 30 '06 #4
Hello NickP,
Hi Jared,

Thanks for the info, so presumably I should be able to elliminate
this issue by changing the current working directory before attempting
to delete said folder? I'll have a try of that, many thanks and much
appreciation :-)


Another quick fix is to set RestoreDirectory to true. That will undo the
directory change as soon as the dialog closes

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
Jun 30 '06 #5

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

Similar topics

0
by: Kong Li | last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset (9.2.0.5) fixed the handle count leak problem. The problem is in Oracle client component. Thanks. Kong ----- From: Kong...
12
by: Ken Brubaker | last post by:
I am using DB2 8.5 FP5 on Windows 2000 Server and have noticed what appears to be a handle leak. When I execute a DB2 connect statement in a command window, followed by a DB2 connect reset...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
4
by: Sharon | last post by:
I’m using OpenFileDialog class in a specific InitialDirectory and I want that files will be selected in the opened dialog when I call ShowDialog(). Actually I wish to select all files in the...
4
by: Chuck Edgeworth | last post by:
I'm trying to be able to select a combination of files and folders. When I try to use the OpenFileDialog it will allow me to select them but when I press the Open button it only informs me of the...
6
by: barbara_dave | last post by:
Hi, All, I want to use the openfiledialog to open different extension files in different directory( only one type files at one time). I set the OpenFiledialog InitialDirectory and Filter...
1
by: =?Utf-8?B?TW9uaWNh?= | last post by:
Hi 1- I want to pick a file in my website project using asp.net 2- I added System.Windows.Forms by add references to my project. 3- I attach a button to my project. 4- in side...
2
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
I need to use the OpenFileDialog class to get the name of a file, but I don't want it to check to see if the file is really there since I may just want to type an arbitrary name in and create it...
1
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
I have a vb.net program that leaks handles as reported by task manager. After running for a couple of hours, task manager reports over 1000 handles, and it continues to grow. I think I am failing...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...

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.