0

I have created a FileSystemWatcher like this:

public FileSystemWatcher CreateFileSystemWatcher(string directory)
{
    FileSystemWatcher watcher = new FileSystemWatcher(directory);

    watcher.IncludeSubdirectories = true;
    watcher.EnableRaisingEvents = true;

    // These are creating objects specific to my application to record changes.
    watcher.Created += OnCreated;
    watcher.Deleted += OnDeleted;
    watcher.Renamed += OnRenamed;
    watcher.Changed += OnChanged;
    watcher.Error += OnError;

    return watcher;
}

The watcher works perfectly as long as I only make changes in the directory that I provided in the constructor. But as soon as I make a change to a file in any subirectory, it records that change and then stops recording changes altogether.

There are some other questions on this site about FileSystemWatchers, but those issues seem to concern the internal buffer size of the watcher, which I don't think is the cause of my problem, as it occurs independently of number and frequency of changes.

Here's another thing I noticed: The way my testing application ist set up is that I start it up, make a bunch of changes, and then press Enter in the console to print them all out. When I only make changes in the watcher's root path, the printing happens immediately, but when I make a change in a subdirectory, it takes a few seconds after I press Enter. Don't know what could cause this but I thought I'd mention it.

TigersEye120
  • 664
  • 1
  • 9
  • 28

0 Answers0