FileSystemWatcher does not report changes in a locked file

后端 未结 6 887
清酒与你
清酒与你 2021-01-01 18:26

I\'m monitoring a folder using a FileSystemWatcher like this:

watcher = new FileSystemWatcher(folder);
watcher.NotifyFilter = NotifyFilters.Size;
watcher.Cha         


        
6条回答
  •  滥情空心
    2021-01-01 18:49

    Yes, Explorer uses the exact same API as FileSystemWatcher uses. There's just one, ReadDirectoryChangesW() as you found out.

    What you found strongly suggest that Win7 is optimizing the disk write that would be needed to update the directory entry for the file. Delaying it until the last possible moment, when the file is closed. There's an interesting correlation between this observation and a critical bug that a user discovered in the RTM version of Win7. The update sometimes doesn't happen at all. The bug strikes randomly but infrequently, I've seen this myself just once on my machine. Knowingly anyway.

    The details are in this thread (beware of very slow server). This still fails today with all Win7 updates applied.

    Well, interesting tidbit but not really germane to your question. You do need to alter your code to accommodate the OS works.

提交回复
热议问题