Search code examples
c#.netdelete-filefilesystemwatcher

FileSystemWatcher not detecting multi-file delete


I have this code to detect deleteing files.

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);
}

But when I delete multiple files using Shift it detects 1 file only.

I know that it should be corrected via WaitForChanged method but I have no clue how to implement it.

The classic code does not help https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.deleted(v=vs.110).aspx

Thanks for help!


Solution

  • I found working solution here

    FileSystemWatcher - Pure Chaos (Part 1 of 2)

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