New FileSystemWatcher Failure Mode

  • Thread starter Thread starter Oscar Bowyer
  • Start date Start date
O

Oscar Bowyer

I've recently discovered a new failure mode for the FileSystemWatcher class.
I'm using FSW in a service to watch and process files in the watched
directory.

The watcher service is running on a different physical machine from the
watched folder.

If the machine with the watched directory is rebooted, the FSW looses its
connection and no longer receives events.

I was looking for an event that would indicate the watched directory had
been disconnected so that the service could attempt to reconnect. No luck.

There is an OnError event, but the docs say that it is fired when the buffer
is overrun.

The only solution I've found is to run the FSW service on the watched
machine. This way the service restarts with the machine.

Anyone using a FSW service to watch different machines needs to consider
this.
 
Hi Oscar,
I've recently discovered a new failure mode for the FileSystemWatcher class.
I'm using FSW in a service to watch and process files in the watched
directory.

The watcher service is running on a different physical machine from the
watched folder.

If the machine with the watched directory is rebooted, the FSW looses its
connection and no longer receives events.

I was looking for an event that would indicate the watched directory had
been disconnected so that the service could attempt to reconnect. No luck.

If you have write access to the watched directory then try periodically
to create a file in that directory and watch whether the certain
event got fired. If not, assume a reboot of the file server and
restart the watcher.

bye
Rob
 
Thanks Robert,

That's an option I hadn't considered.

I was hoping to avoid "polling" techniques. Also, if the disconnect happens
between "polling" intervals, the watcher could still miss events depending
on the interval. I would imagine more than 2 minute interval could miss
events.

The watched server is shutdown very infrequently, so this is mostly a
non-problem but it happened on the first test run.

I also found some new Network classes in .NET 2.0 Beta that might help.

I haven't found a truly bullet proof solution, but this would work better
that most of my other options.

Thanks,
Oscar
 
Oscar Bowyer said:
I've recently discovered a new failure mode for the FileSystemWatcher class.
I'm using FSW in a service to watch and process files in the watched
directory.

The watcher service is running on a different physical machine from the
watched folder.

If the machine with the watched directory is rebooted, the FSW looses its
connection and no longer receives events.

I was looking for an event that would indicate the watched directory had
been disconnected so that the service could attempt to reconnect. No luck.

There is an OnError event, but the docs say that it is fired when the buffer
is overrun.

I am trying to do the same thing -- detect when FileSystemWatcher is
going to stop working on a network share when the network disconnects.
I find that FileSystemWatcher.Error gets called when the network
disconnects and ErrorEventArgs.GetException() returns a "The specified
network name is no longer available" exception. So I watch for those.

- M
 
Back
Top