NotifyFilters.LastWrite ...

问题描述 投票:0回答:1
In Mono's Technical FAQ, you can find a

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

  • Mono falls back to polling the directories for changes, which far from optimal.

Experimentally, I found out that one of these conditions is:


The total number of watched directories is more than 4096WatcherChangeTypes.ChangedThere 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 use
c# .net linux mono filesystemwatcher
1个回答
0
投票

Your NotifyFilter includes

NotifyFilters

.LastAccess

The

command returns more than 4096 在Linux上的沉重CPU负荷


我订阅了一个目录内的变化。

  1. 大多数时候,这段.NET 4.7的代码都能正常工作,但是当它在Debian的Mono下运行时,在某些目录下,我注意到了以下行为。
  2. CPU负载增加到250%(2.5个核心完全加载)子线程的数量增加,它们会给CPU带来负载这样无休止地持续下去,直到应用程序完全卡住。
  3. UPD:另外的研究表明,CPU的重度负载是由无休止的洪流引起的。 监视目录内的每一个子目录的事件(每一个目录连续发生1-2个事件,当所有的目录都被报告为被改变时,它又开始了)。UPD: 最小的错误例子
  4. find watched-directory -type d | wc -l我订阅一个目录里面的变化。FileSystemWatcher watcher = new FileSystemWatcher(directory); watcher.NotifyFilter = NotifyFilters.LastAccess.
© www.soinside.com 2019 - 2024. All rights reserved.