I’ve written a small test application using the .Net FileSystemWatcher to keep an eye on a directory. When I copy a large-ish (a few Mb) file into that directory I get the following events listed (see screenshot – and ignore the Delete event to begin with).
alt text http://robinwilson.homelinux.com/FSW.png
I get a created event (as expected), but then two changed events (about 0.7 seconds apart). Why is this? This would cause major problems in the application I am planning to develop – as I’d try and do things with the file twice (presumably once before it has finished being written to!). Is there anything I can do to stop this happening? From what I’ve read on StackOverflow and elsewhere, you should just get one changed event once the file has been changed and then closed. Why am I getting two?
According to the documentation (see the first bullet point under Events and Buffer Sizes):