FileSystemWatcher event trigger problem(s)

人走茶凉 提交于 2019-12-25 02:58:28

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/2646729/filesystemwatcher-event-trigger-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!