Cannot browse folder using FileSystemWatcher in C #

I am trying to control a folder (and its subfolders) for changes. However, my handler event is never executed. I am using the following code:

FileSystemWatcher m_Watcher = new FileSystemWatcher();
m_Watcher.Path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Portal 2 Map Installer/"; 
m_Watcher.Filter = "";
m_Watcher.NotifyFilter = NotifyFilters.LastAccess |
             NotifyFilters.LastWrite |
             NotifyFilters.FileName |
             NotifyFilters.DirectoryName;
m_Watcher.IncludeSubdirectories = true;
m_Watcher.Changed += new FileSystemEventHandler(OnFolderChange);
m_Watcher.EnableRaisingEvents = true;

Help me please!

+3
source share
2 answers

Create a handler for the error event and see what it says:

  m_Watcher.Error += new ErrorEventHandler(OnError);
0
source

There are several notes in the Changedevent handler:

The Changed event occurs unexpectedly when a file is renamed, but does not occur when a directory is renamed. To view the renaming, use the Renamed event .

Thus, it would be wise to handle the event Renamed(at least).

0
source

All Articles