What is the impact of a FileSystemWatcher on a hard drive?

ぃ、小莉子 提交于 2019-12-29 09:02:43

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/19260188/what-is-the-impact-of-a-filesystemwatcher-on-a-hard-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!