简体   繁体   English

Mac的Mono FileSystemWatcher打开它监视的所有文件

[英]Mono FileSystemWatcher for Mac Opens all the files it watches

I am using Mono 4.6.2 我正在使用Mono 4.6.2

When I create FileSystemWatcher to monitor a directory on Mac, it appears the watcher is opening all the files in that directory. 当我创建FileSystemWatcher来监视Mac上的目录时,观察者似乎正在打开该目录中的所有文件。 I can see this in two ways: 我可以通过两种方式看到这一点:

  1. when I open a large directory, it throws "too many open files" exception. 当我打开大目录时,它会引发“打开文件太多”异常。

  2. I can see all the files are listed under "Activity Monitor->Information->Open Files and Ports" for my program. 我可以看到我的程序的“活动监视器->信息->打开文件和端口”下列出了所有文件。

This is how I created my watcher: 这是我创建观察者的方式:

var watcher = new FileSystemWatcher {
    Path = path.LocalPath,
    IncludeSubdirectories = true
};
watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.FileName | 
                       NotifyFilters.DirectoryName | NotifyFilters.LastWrite;
watcher.Changed += FileSystemWatcher_Changed;
watcher.Renamed += FileSystemWatcher_Renamed;

Is it designed this way? 是这样设计的吗? Is there a workaround for this issue? 有没有解决此问题的方法?

Take a look at this ticket #bugzilla.xamarin . 看看这张票#bugzilla.xamarin

Workaround: run the GC for every iteration. 解决方法:为每次迭代运行GC

//Execute:
mcs test.cs
ulimit -n 96
mono test.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM