By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,983 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,983 IT Pros & Developers. It's quick & easy.

problem with file handles

P: n/a
hi,

in my app i monitor the filesystem for changes with FileSystemWatchers.
When the change is detected the app performs some actions using Shell32
to obtain information from the filesystem. now the problem is that
apparently the CLR not always closes the file handles immediately.
this is rather annoying to the user because he's unable to change
(write, delete, rename) these locked files or directories. the strangest
thing is that some handles are closed at once and some not - this is
totally random. sometimes it takes few minutes before the handle is
closed even if my app does not need those files anymore.

so the question is, how can i force my app to close those unused file
handles?
Apr 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
SharpCoderMP wrote:
hi,

in my app i monitor the filesystem for changes with FileSystemWatchers.
When the change is detected the app performs some actions using Shell32
to obtain information from the filesystem. now the problem is that
apparently the CLR not always closes the file handles immediately.
this is rather annoying to the user because he's unable to change
(write, delete, rename) these locked files or directories. the strangest
thing is that some handles are closed at once and some not - this is
totally random. sometimes it takes few minutes before the handle is
closed even if my app does not need those files anymore.

so the question is, how can i force my app to close those unused file
handles?


You are saying that you are calling the Close method and the system is
not releasing the file?

Chris
Apr 4 '06 #2

P: n/a
Chris wrote:
You are saying that you are calling the Close method and the system is
not releasing the file?


no it's not like that. i have a code like this (this is only example -
it is not my actual code):

Shell32.Folder shell32Folder = SOME_PLACE_TO_START;
foreach (Shell32.FolderItem item in shell32Folder.Items())
{
this.myFileList.Add(item);
}

/* the Shell32 namespace is available
* when you reference the system's Shell32.dll
* the VS IDE will generate a wrapper for it */

as you can see i do not perform any direct file operations. i only use
Shell32 to access some folder data. that's it. what's more the
Shell32.FolderItem does not provide any methods to close the eventual
file handle. the problem is that some file handles that apparently CLR
uses are not closed immediately. note that some handles *are* closed
just after they are used and some remain open for some time. it is
totally random which handles are closed and which not. eventually after
some random amount of time all of the remaining handles are closed. the
problem is that this can take as short as only few seconds or as long as
few minutes - it's just unpredictable. and during that time this files
(or folders) are locked - they cannot be renamed, moved or deleted from
outside of my app.

so is there any way i can force CLR to close those unused file handles?
Apr 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.