0

We search a reliable possibility to get notified when a file was modified by another application.

The .NET FileSystemWatcher class and the ReadDirectoryChangesW() function both suffer from the problem that they generate the event even if the other application has not finished writing yet.

Under Linux, inotify provides an IN_CLOSE_WRITE event - the file was closed after being opened for writing.

Is there any way to get that information on windows?

[Edit for clarification:] I'm primarily interested in when the writer finished its work, not about exclusive access / locking isuses. And I want to avoid polling / repeated try-and-catch-exception like solutions, as those are generally a bad programming style, and event based programming is better for power saving.

Thanks, Markus

MarkusSchaber
  • 747
  • 1
  • 8
  • 16
  • I believe that WMI can do this, but I personally don't know any details. – David Heffernan Feb 17 '12 at 17:10
  • 1
    See http://stackoverflow.com/questions/876473/is-there-a-way-to-check-if-a-file-is-in-use – Diego Feb 17 '12 at 17:14
  • Also http://stackoverflow.com/questions/9182070/c-directory-watching-how-to-detect-copy-has-ended – arx Feb 17 '12 at 18:00
  • @Diego: Thanks, but 876473 is not exactly the same problem. Apart from that, they present no real solution for their problem, but only "polling" / "retrying" in a loop. The most voted / accepted "solution" even includes a race condition. – MarkusSchaber Feb 20 '12 at 07:30
  • @arx: Thanks, 9182070 tries to solve the same problem. But they also find no real solution except polling. – MarkusSchaber Feb 20 '12 at 07:32

0 Answers0