0

I wish to understand how FileSystemWatcher monitors changes.

Is there a central set of Windows system API that are central conduit for creation, removal, changing of file system objects, such that each change causes the API to post a notification that FileSystemWatcher subscribes to?

Or does FileSystemWatcher simply continually polls the path specified looking for differences?

I wrote a C# routine using FileSystemWatcher to watch the entire C drive, and tested it by creating, deleting, renaming files. The response was quite immediate.

Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
  • 1
    You misunderstand what "algorithm" means.... – Dai Nov 17 '22 at 08:48
  • Does this question not already answer yours?: https://stackoverflow.com/questions/71295028/how-does-system-io-filesystemwatcher-works-under-the-hood – ProgrammingLlama Nov 17 '22 at 08:48
  • "Is there a central set of Windows system API that are central conduit for creation, removal, changing of file system objects, such that each change causes the API to post a notification that FileSystemWatcher subscribes to?" - [yes, that's how it works](https://github.com/microsoft/referencesource/blob/master/System/services/io/system/io/FileSystemWatcher.cs). – Dai Nov 17 '22 at 08:48
  • Are you saying this opinion. that FSW continually scans, is wrong: https://www.codeproject.com/Questions/5311384/Filesystemwatcher-on-all-drives – Blessed Geek Nov 17 '22 at 08:51
  • https://github.com/microsoft/referencesource/blob/master/System/services/io/system/io/FileSystemWatcher.cs#L729 – ProgrammingLlama Nov 17 '22 at 08:53
  • No, `FileSystemWatcher` does not "continually scan" your filesystem. The comments in that CodeProject article are factually incorrect: we've linked you to the source-code of `FileSystemWatcher` and you can see it's just a wrapper over Win32's [`ReadDirectoryChangesW`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-readdirectorychangesw). – Dai Nov 17 '22 at 09:06

0 Answers0