[FileSystemWatcher] Missing Notifications

  • Thread starter Thread starter R
  • Start date Start date
R

R

I'm using the FileSystemWatcher class to track changes to a
Windows system logfile. Unfortunately, notifications are not
occurring for write operations on that file.

I'm using the sample code here:

http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

It's modified to contain this:

watcher.Filter = "*.log";

And I've supplied the correct directory name.

Notes:

I can see write operations occurring using Process Monitor, so
I know the log file is being written to. But my program doesn't
get notified. Also, the modification date does not change in a
Windows Explorer view after a write unless I manually refresh
the view. At that point the modified time is seen to change
*and* my program is notified of the LastWrite change. A similar
thing happens if I poll at 1 second intervals and retrieve the last
write time. That is, the LastWrite change notification seems to
appear after I make a System.IO.File.GetLastWriteTime method call.

I hope I've written this clearly enough. I'm not sure if I have.

Any suggestions on how to get this to work would be very welcome
as I'd like to avoid polling (which I know works).

Thanks.
 
cfps.Christian said:
I had some problems with the watcher in the past and the two issues
were:
1. You have to set EnableRaisingEvents to true. Don't know why, but
it defaulted to false.

Yes, I've done that.
2. The FileSystemWatcher has this fun bug where if it receives too
many events too fast it simply gives up. I was using it for file
created and if somewhere along the lines of 50 files were created at a
time the watcher would just stop throwing events completely.

The number of events is likely not very great.

It's almost as if the notifications are trapped and only
released when some other access to the file occurs.

I wonder: is Windows Explorer meant to update the shown
modification times as they change or is one supposed to
click the refresh button to get the latest information?

Thanks.
 
Back
Top