FileSystemWatcher on a network drive that gets disconnected

  • Thread starter Thread starter Adam Clauss
  • Start date Start date
A

Adam Clauss

I have a FileSystemWatcher which I have listening on a network path
(\\server\foldername). I have events wired for files being created and
changed.

I have noticed that if the connection to the path is lost (I can easily
simulate this by pulling the network cable on the fileshare host) that I no
longer receive events. Is there anyway to detect this and recover from it?

Thanks!
 
Adam Clauss said:
I have a FileSystemWatcher which I have listening on a network path
(\\server\foldername). I have events wired for files being created and
changed.

I have noticed that if the connection to the path is lost (I can easily
simulate this by pulling the network cable on the fileshare host) that I
no longer receive events. Is there anyway to detect this and recover from
it?

Thanks!

If your client is directly wired to the server, you could use
System.Management and WMI to watch for "MSNdis_MediaConnectStatus" events,
drop the FileSystemWatcher when a disconnected event arrived and re-create
the FSW after a "connected" event arrived.
However, if you are on a switched network, there is little you can do other
than trying to open a temp. file on the share you are watching at a regular
interval, when this fails you drop the FSW and re-create him back when the
share reconnects.

Willy.
 
Thanks to both for your replies - I will look into both of these. If Eric's
works successfully, it does seem like the simpler of the solutions.
 
I did not try Eric's code, but there are a few things I don't like about it.

Willy.
 
Back
Top