Posted on 2009-03-30
We have a simple Windows Service that we wrote in C# that is supposed to watch a folder and run a batch file when a new file arrives. We have a report that is generated by our legacy system that is supposed to be emailed. The system locks the file when it starts writing to it and only unlocks it once it finsihes. Microsoft has the following in docs:
The OnCreated event is raised as soon as a file is created. If a file is being copied or transferred into a watched directory, the OnCreated event will be raised immediately, followed by one or more OnChanged events.
I think when legacy system has the file locked, the service tries to react to OnCreated and get stuck because at that time the file is locked. We only want the service to run the batch file when file is unlocked hence completed.
How can this situation be handled?