Home > other >  What does "polling" mean in the context of watching for file changes?
What does "polling" mean in the context of watching for file changes?

Time:07-12

I'm currently trying to get a FileSystemWatcher to work, as outlined in this question. During my research, I found a lot of answers and comments on this site describing the unreliability of this class. Instead, "polling" is mentioned in some places as a method of watching for changes, for example in this (very old) answer. My question is what that means exactly.

CodePudding user response:

Polling means here that you regularly read for instance the last write-time of the files you want to watch and test if there is a difference. you could even read the file contents and compare it with a previous verison. Polling just means that you actively do the comparison instead of being notified.

Polling is best avoided for its cost. But if needed then it is needed.

https://en.wikipedia.org/wiki/Polling_(computer_science)

Regarding FileSystemwatcher. It is not perfect but in my experience correct enough in the majority of the cases . I assume that all watchers in developer tools use that mechanism and it is for instance good enough there. I suggest to try it first for your purpose before polling.

  • Related