1

enter image description hereI'm trying to implement a file watcher that will raise an event if the file created. The problem that created event is triggered file has not finished to be written. File still in use,created event triggered before file create finish.

Pavan Modi
  • 77
  • 7
  • 3
    would you pls post the relevant code ........ – Glory Raj Mar 25 '13 at 11:18
  • Why don't you spin-off a background thread that periodically checks if it can obtain a write-lock on it. I would assume that a successful lock indicates that the writing process has completed its initial write. – Chris Sinclair Mar 25 '13 at 11:21
  • Voting to close as the same question has been asked here and has multiple solutions http://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice. (This is a common 'issue' with the FileSystemWatcher) – keyboardP Mar 25 '13 at 11:23
  • Given the screenshot you posted, I don't think there's any real way around this. You state that the "File is still not completely created", only with respect to the operating system it most certainly _is_. You _could_ listen to other events like `Renamed`, `Deleted`, or `Changed` and handle it more generically. (So a new file "New Text Document.txt" is created so you run some `DoActionCreated()` method, then renamed to "SomeOtherName.txt" so you run some `DoActionRenamed()` method) – Chris Sinclair Mar 26 '13 at 17:50

0 Answers0