I have a C# Windows Service that periodically polls a folder and compares its contents to another folder. If necessary, it deletes files. The problem I'm having is that the file does not actually get deleted until the service is stopped. After the attempted deletion, the service can no longer read that file's attributes.
Whenever the service attempts to access the file after attempting to delete it, an "access is denied" exception is raised. When I run Sysinternal's Process Monitor, it reports "DELETE PENDING" when that exception is raised.
I'm accessing the file's extended metadata through a third party component. That component's code is unavailable to me. I've got a feeling that the service is not releasing file handles for some reason, even though I can't determine where. My guess is that it is that component.
My question is this: Short of shutting the program down, how can I force it to release these file handles? Is it simply a matter of clearing out (nullifying) the objects that access the metadata, or is there something I can do at the application (service) level? Is this related to the garbage collector (GC)?
Thanks in advance for your advice.