How does FileSystemWatcher work on another computers directory?

后端 未结 2 543
醉话见心
醉话见心 2021-01-18 11:13

Something intrigues me and I don\'t find any resource on this.

How can FileSystemWatcher know when a file on a computer \"A\" is created/removed/changed/renamed ?

2条回答
  •  礼貌的吻别
    2021-01-18 11:50

    Using FileSystemWatcher on another computer seems too easy to be true...

    It kinda is. The underlying API - ReadDirectoryChanges() - opens up a connection to the server, which is responsible for responding when something changes. If that connection gets dropped for some reason, or you bump up against the connection limit of the OS you're connecting to, then you don't get notifications.

    I've found that it is more reliable to poll periodically (with some rather long interval), and use FileSystemWatcher only as a way of responding quickly to changes in between polls.

提交回复
热议问题