通过谷歌搜索,我了解到“它用于跟踪文件系统操作”。但我不明白它的实用性,观察者可以直接触发事件而无需将其存储在某个中间缓冲区中!!
是否可以将异步事件流(复制/修改文件)转换为同步事件调用?另外,我不确定 FileWatcher 是否异步触发事件。
有人可以解释一下吗?
请您参考如下方法:
我认为您在问题中遗漏了缓冲区的要点。
来自 MSDN, FileSystemWatcher (强调我的):
The Windows operating system notifies your component of file changes in a buffer created by the FileSystemWatcher. If there are many changes in a short time, the buffer can overflow. This causes the component to lose track of changes in the directory, and it will only provide blanket notification.
因此,它不是尚未告诉您的事件缓冲区,而是它为窗口提供的缓冲区,用于首先支持通知,而无需轮询。如果 Windows 在此实例中抛出大量操作,则此缓冲区将溢出,而您(FileSystemWatcher 的消费者/用户)将丢失一些通知。
