May 26, 2009
I have created a Windows service in VS 2005 that monitors a folder for XML files, reads some data elements from the XML using XmlDocument, then copies the files to another location. I find that when I drop 2 or more XML files into the folder simultaneously, it processes them with no problems, but when I drop the same files into the folder one at a time, I will get an error on the second file: "The process cannot access the file <my file> because it is being used by another process." If I stop my service, restart it, and drop the second file into the folder again, it works the second time. I am confident that no other program is accessing this file at the same time as my service. My impression is that the processing of file # 1 is somehow not releasing all of the resources, leading to the processing of file # 2 mistakenly thinking that it can't access that second file.
View 12 Replies
Dim FileWatcher As New FileSystemWatcher()
It points the watcher to my folder, sets up an event handler, then enables the watching:
FileWatcher.Path = InputFolderPath