C#/WPF FileSystemWatcher on every extension on every path

不问归期 提交于 2020-01-05 05:34:19

问题


I need FileSystemWatcher, that can observing same specific paths, and specific extensions. But the paths could by dozens, hundreds or maybe thousand (hope not :P), the same with extensions. The paths and ext are added by user.

Creating hundreds of FileSystemWatcher it's not good idea, isn't it?

So - how to do it? Is it possible to watch/observing every device (HDDs, SD flash, pendrives, etc.)? Will it be efficient? I don't think so... . Every changing Windows log file, scanning file by antyvirus program - it could realy slow down my program with SystemWatcher :(


回答1:


Well try first and then you'll see if you run into troubles.

Trying to optimize something where you don't even know if there is a problem is usually not very effective.




回答2:


You're probably right that creating 10,000+ FileSystemWatchers may cause a problem. If it does (as Foxfire says - test it), start with the easy consolidations -- ignore the extensions when setting up your FileSystemWatchers, and filter the events after you get them.

If that still results in too much resource usage, try intelligently combining paths in the same manner, perhaps even going so far as to only create one FileSystemWatcher per drive letter, and perform the rest of your filtering after the event is received by your code.



来源:https://stackoverflow.com/questions/2704440/c-wpf-filesystemwatcher-on-every-extension-on-every-path

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