Click here to Skip to main content
12,956,197 members (103,932 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How to find the filesystemwatcher is disconnected or not. if disconnected i want to reboot the filesystemwatcher please give solution.
Posted 28-Jul-12 6:36am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I personally have written my own file system watcher that inherits FileSystemWatcher. I had the need to monitor external USB drives that were not always connected when my application was started. So first off if the drive is not connected then EnableRaisingEvents will fail, I have a custom routine that checks for the destination folders existance and when it exists will then trigger EnableRaisingEvents. If/when the drive gets disconnected the FileSystemWatcher raises the Error event which triggers my routine to start monitoring for that folders existence again. I also have a builtin routine that monitors the last event from the FileSystemWatcher and if it has been longer than X minutes since the last event then it will disable raising events and then try and re-enable raising events. It has been successful in heavy use for several years now.

So, long story shorter check the EnableRaisingEvents property (true == working, false == not working) and add a handler to the Error event, this will be triggered when mass files get dumped and there is a buffer overrun, or drive disconnected etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,869
CHill60 3,550
Maciej Los 3,243
ppolymorphe 2,070
Jochen Arndt 1,973

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 28 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100