FileSystemWatcher under mono - watching subdirs

不想你离开。 提交于 2019-12-04 07:37:48

As far as I can tell, this simply does not work in Mono on OS X. I encountered it last week and could not find any bug report for it, so I reported it here: https://bugzilla.xamarin.com/show_bug.cgi?id=16259

As far as I can follow the implementation of KEventWatcher, it doesn't do anything to subscribe to subdirectories when the watcher is created. I think the only time it subscribes to subdirectories is when it detects them being added in PostEvent. Even if it did subscribe to all subdirectories on creation, it might not be a great solution. The underlying kevent mechanism would require an open file descriptor for every subdirectory, which could end up being an awful lot of file descriptors.

Mono does have other implementations of the FileSystemWatcher, but I believe the selection of implementation is baked into the Mono runtime when it's compiled. There is a slow and inefficient default watcher that works on all platforms by simply scanning the entire directory tree every second or so, but it is only selected if there isn't a platform-specific implementation available.

I'm afraid to say, it looks like your best bet are either of the workarounds you suggest - scanning for changes manually or creating a FileSystemWatcher for every directory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!