Problem with FileSystemWatcher generating FileCreated event:
I have a windows service which picks up a file from a folder-Request, then does some processing and writes to another folder-Response. I have implemented FileSystemWatcher component in the windows service to watch for new files in the Request folder and in FileCreated event handler, I wrote the code to process the file. It works perfectly fine when I manually drop the test file in the Request folder. But when my BizTalk application writes the same file in the Request folder, the windows service fails to process the file.
This seems to be an issue I could not find any documentation from Microsoft. The exact problem, what I could guess, is: either the FileSystemWatcher generates the FileCreated event at the time of File handler is created but the file is still being written and yet to be closed. Or the file is written but lock is yet to be released.
After some experimentation, I could find a work around: Use a few seconds delay in the first line of the FileCreated event handler:
System.Threading.Thread.Sleep(3000);
This gives enough time to release the file lock, and Windows service can pick up the file and process successfully.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment