What are the issues with FileSystemWatcher?
FileSystemWatcher watcher = new FileSystemWatcher(directory);
watcher.NotifyFilter = NotifyFilters.LastAccess;
watcher.Changed += OnChanged;
watcher.IncludeSubdirectories = includeSubdirectories;
watcher.EnableRaisingEvents = true;
section, which says that under certain conditions
Experimentally, I found out that one of these conditions is:
The total number of watched directories is more than 4096WatcherChangeTypes.Changed
There may be more conditions related to files count, but I did not met them.
So, you may face the described problem if the following conditions are met:You run a .NET Framework 4.7 code under Mono 6.8 on Linux (or in Docker)
You useYour NotifyFilter includes
NotifyFilters.LastAccess
The
我订阅了一个目录内的变化。
find watched-directory -type d | wc -l
我订阅一个目录里面的变化。FileSystemWatcher watcher = new FileSystemWatcher(directory); watcher.NotifyFilter = NotifyFilters.LastAccess.