FileSystemWatcher - implementation detail

T

Tim

I'm trying to use a FileSystemWatcher object to monitor
changes to a network directory. I understand that if I
try to assign an un-available directory to the Path
property it will throw an exception to let me know the
path is invalid. But is there any way to find out if and
when a network directory that is initially available when
the Path is assigned subsequently becomes invalid once
the FileSystemWatcher is active and monitoring the
directory?
Secondly, can anyone tell me how frequently the
FileSystemWatcher will poll the directory it is watching
and if there is any way to configure this?
 
N

Nick Wienholt

is there any way to find out if and
when a network directory that is initially available when
the Path is assigned subsequently becomes invalid once
the FileSystemWatcher is active and monitoring the
directory?

I'm not sure if Windows even knows that the directory is no longer
available. WMI would be the most likely candidate for monitoring this type
of stuff, but the Win32_VolumeChangeEvent notes that "(monitoring of
n)etwork drives are not currently supported". Polling would probably be the
only option.
Secondly, can anyone tell me how frequently the
FileSystemWatcher will poll the directory it is watching
and if there is any way to configure this?

It doesn't poll. The event-based ReadDirectoryChangesW function is used.

Nick Wienholt, MVP
Maximizing .NET Performance
http://www.apress.com/book/bookDisplay.html?bID=217
Sydney Deep .NET User Group www.sdnug.org
 
D

Dave Loynd

Tim said:
I'm trying to use a FileSystemWatcher object to monitor
changes to a network directory. I understand that if I
try to assign an un-available directory to the Path
property it will throw an exception to let me know the
path is invalid. But is there any way to find out if and
when a network directory that is initially available when
the Path is assigned subsequently becomes invalid once
the FileSystemWatcher is active and monitoring the
directory?

Yes, FileSystemWatcher will throw an Error event when a network resource is
no longer available and disable raising events.
Secondly, can anyone tell me how frequently the
FileSystemWatcher will poll the directory it is watching
and if there is any way to configure this?

Like Nick said, there is no polling.
 

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