1

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 -

  • Is this the correct way of doing this?
  • Polling the directory every 3 (or any arbitrary 'x' seconds) to see if it still exists defeats the purpose of using the FSW, I could instead use the polling method to look for the new files and handle it accordingly.
  • I have no clear indication anywhere that this is the expected behavior of FSW, so, could it be a framework 4.0 bug?

Note: We came this current solution based on these articles -

Community
  • 1
  • 1

1 Answers1

1

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.

user469104
  • 1,206
  • 12
  • 15
  • The network drive we are using is not a SAN drive, it is a standard windows server file share. I think we have narrowed down the issue.. We found that there was an issue with the network adapter on that server and that's the reason it goes down silently. We will be implementing a polling + FSW solution so that it is more robust.. – user129615212 Aug 21 '14 at 07:44