FileSystemWatcher 未检测到多文件删除

FileSystemWatcher not detecting multi-file delete

我有这个代码来检测删除文件。

m_Watcher = new System.IO.FileSystemWatcher();
m_Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
m_Watcher.Changed += new FileSystemEventHandler(OnCreated);
m_Watcher.Created += new FileSystemEventHandler(OnChanged);
m_Watcher.Deleted += new FileSystemEventHandler(OnDeleted);
m_Watcher.Renamed += new RenamedEventHandler(OnRenamed);
m_Watcher.EnableRaisingEvents = true;



private void OnDeleted(object sender, FileSystemEventArgs e)
{
    Debug.WriteLine(e.FullPath);
}

private void OnChanged(object sender, FileSystemEventArgs e)
{
     Debug.WriteLine(e.FullPath);
}

但是当我使用 Shift 删除多个文件时它只检测到 1 个文件。

我知道应该通过WaitForChanged方法更正,但我不知道如何实现它。

经典代码没有帮助https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.deleted(v=vs.110).aspx

感谢帮助!

我在这里找到了可行的解决方案

FileSystemWatcher - Pure Chaos (Part 1 of 2)

http://www.codeproject.com/Articles/58740/FileSystemWatcher-Pure-Chaos-Part-of