FileSystemWatcher on a network drive that gets disconnected

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!
 
W

Willy Denoyette [MVP]

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.
 
A

Adam Clauss

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.
 
W

Willy Denoyette [MVP]

I did not try Eric's code, but there are a few things I don't like about it.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top