我有一个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;
Run Code Online (Sandbox Code Playgroud)
这是我的OnCeated方法
void OnCeated(object sender, FileSystemEventArgs e)
{
XDocument xmlDoc = BeginImport(e.FullPath);
}
Run Code Online (Sandbox Code Playgroud)
知道为什么这只是为第一个文件夹复制到监视目录中的事件触发了吗?