FileSystemWatcher does not report changes in a locked file

后端 未结 6 886
清酒与你
清酒与你 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:55

    Looks like the file data is cached and not actually written. When you write something to the file, the data is first placed to cache using certain file system IRP (driver request). Now when the data is actually written to the disk, another IRP is sent. It can be (this is a guess) that FileSystemWatcher catches only second IRP type.

    The solution (if possible) is to call Flush on the file you are writing. If you are tracking changes made by other applications, things can become more complicated, of course.

提交回复
热议问题