FileSystemWatcher Traps

I am working on a C # program that should use a class FileSystemWatcher, so it will be notified when new files are created. As part of the initialization, the program scans the directory so that it can process any files that already exist in it. It all works fine.

However, during a discussion with another developer, we started asking the question whether this will always work. Are there conditions under which FileSystemWatcherskipping file creation? If so, what are these conditions?

To deal with this scenario, we simply run the code in our initialization process, which periodically scans the directory, but how likely is it to FileSystemWatcherskip files?

+4
source share
3 answers

FileSystemWatcherusually does not skip files. But:

  • since it is based on ReadDirectoryChangesW, it only detects changes to the file directory entries, not changes to the file itself. Most changes to the file will update the entry in the directory, but there are a few exceptions (see this article ).
  • the buffer for file change notifications has a limited size; if you don’t handle events fast enough, the buffer will overflow, which will skip events. This is why you should not do heavy processing in an event handler; if you cannot handle events fast enough, just add them to the queue that you are processing in another thread.

Other traps:

  • ; , , . , , , .
  • Moved. , : Deleted Created
  • , , 8.3 (, SOMETH~1.TXT Something.txt)
  • , , , . .
  • Changed ; .
+11

FileSystemWatcher - , , , .

+2

fs- , , FSwatcher ( ), , - - "gigs", , , -, , . fswatcher , , FSwatcher . , , , , , . , FSwatcher, . , , Windows -. , - filestream, , , , , , , , , . , , - , , , 5 , , , bg , , , (, , ).

FSwatcher, , , , , . , , , , , , ! , , , :)

0

All Articles