Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileSystemWatcher on mapped network drive

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?

like image 725
Jess Avatar asked Jul 17 '11 16:07

Jess


1 Answers

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

  1. You can check the connection via File.Exists or Folder.Exists.
  2. The FileSystemWatcher will 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, the FSW will no longer handle any data even if the connection is reestablished, so handle FileSystemWatcher.Error event and if the error is raised, reset EnableRaisingEvents to true again, or reinitialize the FSW
like image 183
Jalal Said Avatar answered Nov 13 '22 16:11

Jalal Said