FileSystemWatcher vs polling to watch for file changes

后端 未结 13 2441
一个人的身影
一个人的身影 2020-11-22 05:44

I need to setup an application that watches for files being created in a directory, both locally or on a network drive.

Would the FileSystemWatcher or p

13条回答
  •  无人共我
    2020-11-22 05:49

    The FileSystemWatcher may also miss changes during busy times, if the number of queued changes overflows the buffer provided. This is not a limitation of the .NET class per se, but of the underlying Win32 infrastructure. In our experience, the best way to minimize this problem is to dequeue the notifications as quickly as possible and deal with them on another thread.

    As mentioned by @ChillTemp above, the watcher may not work on non-Windows shares. For example, it will not work at all on mounted Novell drives.

    I agree that a good compromise is to do an occasional poll to pick up any missed changes.

提交回复
热议问题