How to handle error thrown by filesystemwatcher object

Description :

When watching the file system, there may be so many events get occurred to be handled by filesystemwatcher object.When too many events occur, the FileSystemWatcher throws the Error event. To capture the Error event, follow these steps:

1. Create a new FileSystemWatcher object, specifying the directory in the Path
2. Register for the Error event.
3. Turn on events by setting EnableRaisingEvents to true.
The following code snippet demonstrates this process:

C# Code

FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"c:\";
// Register for events
watcher.Error +=
new ErrorEventHandler(watcher_Error);
// Start Watching
watcher.EnableRaisingEvents = true;
// Event Handler
static void watcher_Error(object sender,
ErrorEventArgs e)
Console.WriteLine("Error: {0}",


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: