Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / April 2006

Tip: Looking for answers? Try searching our database.

problem with file handles

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SharpCoderMP - 04 Apr 2006 14:09 GMT
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?
Chris - 04 Apr 2006 14:38 GMT
> hi,
>
[quoted text clipped - 10 lines]
> 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
SharpCoderMP - 05 Apr 2006 10:46 GMT
> 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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.