Detecting when a file has changed on disk?

  • Thread starter Thread starter Robin Tucker
  • Start date Start date
R

Robin Tucker

In the absence of IAdviceSink support in .NET (well, not the pure vanilla
COM version anyway), I need to be able to tell when another process has
saved changes to a file, in a similar way some programs state "file has
changed on disk, reload?". I was wondering what strategy I should use in
order to check temp files I have created to see if they have been changed by
another process. My initial thought is to periodically check the files, but
if there are (say) 20 of them, this could in time become quite a drag on
performance.

Any other strategies I can use?


Robin
 
Robin,

There is a the filesystemwatcher class, I think that does what you ask.

This I copied from that class documentation

There are several types of changes you can watch for in a directory or file.
For example, you can watch for changes in Attributes, the LastWrite date and
time, or the Size of files or directories. This is done by setting the
FileSystemWatcher.NotifyFilter property to one of the NotifyFilters values.
For more information on the type of changes you can watch, see
NotifyFilters.

I hope this is something you mean?

Cor
 
Back
Top