We are using FileSystemwatcher to look for certain files in a directory and it goes down sometimes. We have handled the file system watcher's Error event and restart the watcher gracefully as mentioned in the question here -> FileSystemWatcher stops catching events
But on several occasions, the network connectivity of the server has gone down and the error event was never raised. So, we used a small method to keep polling the directory every 3 seconds using
if(!Directory.Exists(NetWorkPath)){
Logger.Log("Error! The directory doesn't exist");
}
and this seems FSW to trigger the Error event correctly.
Questions -
Note: We came this current solution based on these articles -
Using a FileSystemWatcher on a network drive (I am assuming that is what you are doing given the network connectivity mention) is a risky proposition at best. Even with SANs and local drives events can be lost if the volume of files being created / deleted is high enough and on a regular network drive it is even more unreliable.
Implementing a polling solution, crude as it may seem, would be a more reliable solution.