Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
Hi,
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
mohanns786

1 solution

Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 322
1 Nirav Prabtani 268
2 _Amy 170
3 Mika Wendelius 165
4 Richard Deeming 155
0 Nirav Prabtani 265
1 OriginalGriff 177
2 _Amy 170
3 Mehdi Gholam 105
4 Maciej Los 90


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 28 Jul 2012
Copyright © CodeProject, 1999-2014
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