首页 > 解决方案 > FileSystemSafeWatcher 缺少已复制的文件

问题描述

我目前正在使用FileSystemSafeWatcher来克服由 File System Watcher 引起的问题。(参考:有没有一种简单的方法可以在 C# 中避免或停止 FileSystemWatcher 两次引发事件?

当试图监视大约 400 个图像的复制事件的文件夹时,只会触发大约 300 个事件。文件可以从https://drive.google.com/file/d/1bcmQw4P79p9FCS2E0k_UKr5hKiQLZCgQ/view?usp=sharing下载

我不明白是什么导致了这个问题。

复制的事件

void copied(object sender, FileSystemEventArgs e)
        {
       // Printing to check if the If condition causes the issue
       System.Diagnostics.Debug.WriteLine("||| > " + robotprocesslist.Count);

   if (ImageExtensions.Contains(Path.GetExtension(e.FullPath).ToUpperInvariant()))
            {
              try
                {

                    if (processedfiles.Any(sublist => sublist.Contains(e.FullPath)) == true)
                    {
                        processedfiles.Remove(e.FullPath);
                    }
                    robotprocesslist.Add(e.FullPath);
                    System.Diagnostics.Debug.WriteLine("--> " + robotprocesslist.Count);


                }
                catch (Exception error)
                {

                }


            }

        }

挂钩到复制的事件

 watcher = new FileSystemSafeWatcher(@watchpath);
 watcher.ConsolidationInterval = 500;
 watcher.EnableRaisingEvents = true;
 watcher.Created += copied;
 watcher.Changed += Watcher_Changed;

标签: c#.netfilesystemsfilesystemwatchersystem.io.file

解决方案


推荐阅读