【发布时间】:2012-09-19 12:09:37
【问题描述】:
我有一个FileSystemWatcher,我想为复制到监视目录的每个文件夹触发一个OnCreated event。将手动将多个文件夹一次复制到此监视目录中。
目前它只为复制的第一个文件夹触发event。
因此,如果我正在查看文件夹 X 并在 Windows 资源管理器中选择文件夹 A、B、C 并将它们复制到 X 中,OnCreated 会为 A 而不是 B 或 C 触发。
这是我用来设置FileSystemWatcher的代码:
watcher = new System.IO.FileSystemWatcher(watchPath);
watcher.InternalBufferSize = 32768;
watcher.IncludeSubdirectories = true;
watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName |
NotifyFilters.CreationTime | NotifyFilters.LastWrite;
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
这是我的OnCeated 方法
void OnCeated(object sender, FileSystemEventArgs e)
{
XDocument xmlDoc = BeginImport(e.FullPath);
}
知道为什么这只会触发复制到监视目录中的第一个文件夹的事件?
【问题讨论】:
标签: c# .net filesystemwatcher