A FileSystemWatcher is very handy for
monitoring a file and e.g. reading it when it’s changed.

However, in some scenarios, more than
one Changed event with the same contents is raised for the same text
file. E.g. NotePad raises the event twice when saving a file, TextPad
3 times etc. etc.

This is annoying, because we don’t
really know how many times the event will be raised, and we can’t
safely react until the last time it’s raised – it may throw e.g. an
Access Denied because the editor isn’t done.

One solution is to use a timer which is
reset every time the event is raised for a specific file. When the
timer runs out, then the file can be accessed. For small files on a
fast machine or connection, it should be fairly safe to set the timer
to 1 sec, but it’ll depend on the size of the file, the load on the
machine, the bandwidth of the connection etc.

Small XML configuration files on a fast
machine with local harddrive storage could probably go as low as
100ms, but a 1 sec timer is safer and the rest of the application
won’t know when the file was available anyway. It just looks to the
app like the user pushed Save 1 sec later. (This could be a problem
when monitoring files in time-critical apps, but then this solution
really shouldn’t be used in such scenarios.)

The ”one timer per file” makes the
solution a lot less attractive the more files are monitored.