Are there any special considerations (other than permissions) that you should take into account when implementing a FSW to monitor a mapped network drive. Will the FSW throw an exception if the drive loses its connection? If not (or if I just catch/handle that exception), will it be sufficient to poll the DirectoryInfo.Exists property to verfity the connection?
Asked
Active
Viewed 1.1k times
1 Answers
7
Well, I have used the FileSystemWatcher to monitor a shared folder that exists on another computer in the network, and here is my experience:
- You can check the connection via
File.ExistsorFolder.Exists. - The
FileSystemWatcherwill not throw an exception if the you lose connection to that shared folder. Instead, whenever the connection is lost you will get this error message: "The specified network name is no longer available". When you get that error, theFSWwill no longer handle any data even if the connection is reestablished, so handleFileSystemWatcher.Errorevent and if the error is raised, resetEnableRaisingEventstotrueagain, or reinitialize theFSW
Jess
- 2,991
- 3
- 27
- 40
Jalal Said
- 15,906
- 7
- 45
- 68
-
3I ran across this same issue with a FSW I was using. But, at least with .NET 4, I found that all I needed to do after the share came back was to set `EnableRaisingEvents` to `false` (actually did this in the FSW_Error handler) and then when the share came back set `EnableRaisingEvents` to `true`. It started picking up events again. – Jim Sep 05 '12 at 19:35
-
Good to know, that is better than reinitialize :) – Jalal Said Sep 06 '12 at 07:14