How to set filter for FileSystemWatcher for multiple file types?

后端 未结 6 1129
醉酒成梦
醉酒成梦 2020-12-08 13:16

Everywhere I find these two lines of code used to set filter for file system watcher in samples provided..

FileSystemWatcher watcher = new FileSystemWatcher(         


        
6条回答
  •  不知归路
    2020-12-08 13:19

    A quick look in the reflector shows that the filtering is done in .Net code after the windows api has reported the file system change.

    I'd therefore suggest that the approach of registering multiple watchers is inefficient as you're putting more load on the API causing multiple callbacks and only one of the filters will match. Much better to just register a single watcher and filter the results yourself.

提交回复
热议问题