1

When using FileSystemWatcher and setting the watcher.IncludeSubdirectories = true.
I am only able to capture changes to subdirectories two levels down (e.g Dir/SubDir1/SubDir2). But if I want something past that directory (e.g. Dir/SubDir1/SubDir2/.../...) no event will be raised.

I maxed out the InternalBufferSize = 65536. Is there a way to be able to get in deeper nested subfolders?

This is to be ran and tested on a network drive folder:

using (FileSystemWatcher _watcher = new FileSystemWatcher())
{

    _watcher.Path = directory;
    _watcher.IncludeSubdirectories = true;

    _watcher.NotifyFilter = NotifyFilters.LastWrite
                        | NotifyFilters.FileName
                        | NotifyFilters.DirectoryName;

    _watcher.Changed += new FileSystemEventHandler(Program._watcher_Changed);
    _watcher.Created += new FileSystemEventHandler(Program._watcher_Changed);
    _watcher.Deleted += new FileSystemEventHandler(Program._watcher_Changed);
    _watcher.Renamed += new RenamedEventHandler(Program._watcher_Renamed);
    _watcher.Filter = "*.*";
    _watcher.InternalBufferSize = 65536;
    _watcher.EnableRaisingEvents = true;

    Console.WriteLine("Press 'q' to quit the sample.");
    while (Console.Read() != 'q');
}
Jimi
  • 29,621
  • 8
  • 43
  • 61
  • [FileSystemWatcher is not reliable](https://bytes.com/topic/net/answers/460919-filesystemwatcher-unreliable) and [FileSystemWatcher vs. polling to watch for file changes](https://stackoverflow.com/questions/239988/filesystemwatcher-vs-polling-to-watch-for-file-changes) – John Wu May 04 '19 at 00:06
  • The BufferSize is unrelated and there's no actual limit (except the System/.Net version defaul `MAX_PATH` and long paths handling). There's something wrong somewhere else: it's a network folder. If you perform the same test on a local drive, you'll see that only the general limitation applies. – Jimi May 04 '19 at 00:14

0 Answers0