Question

I've used FileSystemWatcher in the past. However, I am hoping someone can explain how it actually is working behind the scenes.

I plan to utilize it in an application I am making and it would monitor about 5 drives and maybe 300,000 files.

Does the FileSystemWatcher actually do "Checking" on the drive - as in, will it be causing wear/tear on the drive? Also does it impact hard drive ability to "sleep"

This is where I do not understand how it works - if it is like scanning the drives on a timer etc... or if its waiting for some type of notification from the OS before it does anything.

I just do not want to implement something that is going to cause extra reads on a drive and keep the drive from sleeping.

Was it helpful?

Solution

Nothing like that. The file system driver simply monitors the normal file operations requested by other programs that run on the machine against the filters you've selected. If there's a match then it adds an entry to an internal buffer that records the operation and the filename. Which completes the driver request and gets an event to run in your program. You'll get the details of the operation passed to you from that buffer.

So nothing actually happens the operations themselves, there is no extra disk activity at all. It is all just software that runs. The overhead is minimal, nothing slows down noticeably.

OTHER TIPS

The short answer is no. The FileSystemWatcher calls the ReadDirectoryChangesW API passing it an asynchronous flag. Basically, Windows will store data in an allocated buffer when changes to a directory occur. This function returns the data in that buffer and the FileSystemWatcher converts it into nice notifications for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top