Filesystemwatcher导致“一次在目录C:\中错误太多更改" [英] Filesystemwatcher causing "Error too many changes at once in directory C:\"

查看:67
本文介绍了Filesystemwatcher导致“一次在目录C:\中错误太多更改"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与其他一些人一样,我在执行文件系统监视程序时收到错误在目录C:\中一次错误太多更改".现在,如果是c:\,很明显有很多更改.但是在这种特殊情况下,我设置了以下参数:

Like a few others I'm getting the error "Error too many changes at once in directory C:\" from the filesystemwatcher when he does its job. Now if it is c:\ it is clear that there are many changes. BUT in this special case I set the following parameters:

Path = C:\
Filter = "test1.txt"
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName
IncludeSubdirectories = true

我启动了观察程序,让它运行了4个小时没有问题,此后Í锁定了计算机,不久后又回来,突然出现错误.

I started the watcher and let it run without problems for 4 hours after which Í locked the pc and came back a short while later and suddenly had the error.

现在我想知道在这种情况下是什么引起了错误.我在这里忽略了重要的事情吗?还是可以通过includesubdirectories参数让它检查c:\的所有子目录,而忽略C:\中存在的单个文件的过滤器?

Now I'm wondering what could have caused the error in this case. Am I overlooking something important here? OR could it be taht the includesubdirectories parameter lets it check ALL subdirectories of c:\ and ignoring the filter of the single file that exists in C:\ ?

推荐答案

您可以增加更改的缓冲区-这对我有帮助.

You can increase the Buffer for changes - this helped me once.

但是要在C:\下查找带有子目录的所有更改,可能会导致大量的工作量.

But to look for every change at C:\ with subdirs can maybe cause a lot of workload..

MSDN FileSystemWatcher.InternalBufferSize属性

仅在筹集方法"中检查过滤器-因此,内部的每个更改都可以被类识别.

The Filter gets only checked at the Raising-Method - so internally every change gets recognized by the class.

我看了看框架代码如您所见,主要的饲养方法.....

I took a look into the framework code as you can see the main 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)"-看起来像这样:

is using this method: "this.MatchPattern(name)" - which look like this:

    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)));
    }

并且您可以看到-此处检查了过滤器-直到很晚才抑制了负载......所以唯一的办法就是增加缓冲区的大小!

and as you can see - the filter get checked here - far to late to have suppressed load... ...So the only way is to increase the buffer size!

这篇关于Filesystemwatcher导致“一次在目录C:\中错误太多更改"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆