您可以增加更改的缓冲区 - 这曾经帮助过我。
但是使用子目录查找 C:\ 中的每个更改可能会导致大量工作量。
MSDN FileSystemWatcher.InternalBufferSize 属性 http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.internalbuffersize(v=vs.110).aspx
EDIT:
过滤器仅在 Raising-Method 处进行检查 - 因此在内部,每个更改都会被类识别。
我查看了框架代码
正如你所看到的主要饲养方法......
private void NotifyFileSystemEventArgs(int action, string name)
{
if (this.MatchPattern(name))
{
switch (action)
{
case 1:
this.OnCreated(new FileSystemEventArgs(WatcherChangeTypes.Created, this.directory, name));
return;
case 2:
this.OnDeleted(new FileSystemEventArgs(WatcherChangeTypes.Deleted, this.directory, name));
return;
case 3:
this.OnChanged(new FileSystemEventArgs(WatcherChangeTypes.Changed, this.directory, name));
return;
}
}
}
正在使用这个方法:“this.MatchPattern(name)” - 看起来像这样:
private bool MatchPattern(string relativePath)
{
string fileName = System.IO.Path.GetFileName(relativePath);
return ((fileName != null) && PatternMatcher.StrictMatchPattern(this.filter.ToUpper(CultureInfo.InvariantCulture), fileName.ToUpper(CultureInfo.InvariantCulture)));
}
正如你所看到的 - 过滤器在这里被检查 - 抑制负载已经太晚了......
...所以唯一的办法就是增加缓冲区大小!