FileSystemWatcher on a mapped network drive

Are there any special considerations (other than permissions) that should be considered when implementing FSW to monitor a mapped network drive. Will the FSW change the exception if the drive loses connection? If not (or if I just catch / handle this exception), will it be enough to poll the DirectoryInfo.Exists property to confirm the connection?

+6
source share
1 answer

Well, I used FileSystemWatcher to monitor the shared folder that exists on another computer on the network, and here is my experience:

  • You can check the connection through File.Exists or Folder.Exists .
  • FileSystemWatcher will not throw an exception if you lose the connection to this shared folder. Instead, whenever the connection is lost, you will receive this error message: " The specified network name is no longer available . When you receive this error, the FSW will no longer process any data, even if the connection is restored, so handle the event FileSystemWatcher.Error , and if an error is raised, reset EnableRaisingEvents to true again or reinitialize FSW
+6
source

Source: https://habr.com/ru/post/892945/


All Articles