4

I'm using the FileSystemWatcher class to monitor a file for changes in size. The software that is writing to the file keeps a stream open and writes about every five seconds.

The changed event is only firing when I have the Windows Explorer open and click "refresh" to force Windows to update the listed size of the file. (Windows 7 specifically.)

I know the FileSystemWatcher is kind of pokey, but are there any solutions here besides periodically polling the file with FileInfo? E.g. can I get Windows to update its file stats more frequently?

Note that the "ModifiedAt" time stamp is never updated after the writing software opens the handle to the file. Not sure if Windows uses updates to the ModifiedAt stamp to trigger re-calculating other file stats. I've tried all of the NotifyFilters and none are triggered without forcing Windows to update its file stats.

Relates to: At what times are files updated on windows

Community
  • 1
  • 1
ZachB
  • 13,051
  • 4
  • 61
  • 89
  • According to the remarks here http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx you could check several properties of the file, not only the ModifiedAt (using NotifyFilter) – Icepickle Jan 18 '15 at 13:59
  • Indeed; I'm using the size and attributes NotifyFilters already. Thanks. – ZachB Jan 18 '15 at 17:31
  • Sorry, i didn't see it from the question – Icepickle Jan 19 '15 at 15:52
  • No worries. Edited the question to clarify that. – ZachB Jan 19 '15 at 20:21
  • My experience with `FileSystemWatcher` has not been good. I would recommend polling with `Fileinfo`. Perhaps you could investigate the possibility of using Windows API calls? http://stackoverflow.com/questions/931093/how-do-i-make-my-program-watch-for-file-modification-in-c – SSS Feb 03 '15 at 06:23

1 Answers1

-1

You need to use a timer it will fire up as soon as an event occurs or status changes. You don't need to there refreshing explorer it will fire even if the explorer is not open.

  • Periodic polling is one of the work-arounds I listed in my question. – ZachB Feb 02 '15 at 16:38
  • Well I then think you need to use maybe FileSystemWatcher but I don't know of other way unless you can create your own function that will keep an eye on the file change state nor event but still I guess that will also fall under periodic polling as it will periodically polling the status of the file. – Mlungisi Ndlela Feb 03 '15 at 03:28