FileSystemWatcher 事件触发问题

发布于 2024-08-29 04:54:27 字数 599 浏览 4 评论 0原文

看起来,FileSystemWatcher 不止一次触发事件。这是我的设置;

 watcher = new FileSystemWatcher();
 watcher.Path = @"D:\testSpace";
 watcher.InternalBufferSize = 1024*64;
 watcher.Deleted += Triggered;
 watcher.Changed += Triggered;
 watcher.Created += Triggered;
 watcher.Error += ErrorOccured;
 watcher.NotifyFilter = NotifyFilters.LastWrite;
 watcher.IncludeSubdirectories = true;

 watcher.EnableRaisingEvents = true; 
  • 如果更改文档,文档更改事件会触发两次。

  • 除非在文件夹下创建新文件,否则不会触发新文件夹创建事件。

    除非在文件夹下创建
  • 删除的事件未触发(也尝试使用shift删除)

你们知道解决这些问题的方法吗?

It seems like , FileSystemWatcher triggers events more than once. Here is my settings ;

 watcher = new FileSystemWatcher();
 watcher.Path = @"D:\testSpace";
 watcher.InternalBufferSize = 1024*64;
 watcher.Deleted += Triggered;
 watcher.Changed += Triggered;
 watcher.Created += Triggered;
 watcher.Error += ErrorOccured;
 watcher.NotifyFilter = NotifyFilters.LastWrite;
 watcher.IncludeSubdirectories = true;

 watcher.EnableRaisingEvents = true; 
  • If you change a document , Document changed event triggered twice.

  • New folder created event does not get triggered unless a new file created under the folder.

  • Deleted event not fired ( tried using shift delete as well)

do you guys know any work around for these issues ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅忆流年 2024-09-05 04:54:27

FileSystemWatcher

常见的文件系统操作可能
引发多个事件。为了
例如,当文件从一个
目录到另一个,几个
OnChanged 和一些 OnCreated 和
可能会引发 OnDeleted 事件。
移动文件是一项复杂的操作
由多个简单的
操作,因此筹集了多个
事件。同样,一些应用程序
(例如防病毒软件)
可能会导致额外的文件系统
检测到的事件
文件系统观察器。

链接中描述了第一个问题的解决方案。

FileSystemWatcher:

Common file system operations might
raise more than one event. For
example, when a file is moved from one
directory to another, several
OnChanged and some OnCreated and
OnDeleted events might be raised.
Moving a file is a complex operation
that consists of multiple simple
operations, therefore raising multiple
events. Likewise, some applications
(for example, antivirus software)
might cause additional file system
events that are detected by
FileSystemWatcher.

The solution to your 1st issue is described in the link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文