问题描述
嘿,我感到困惑的是如何使用文件系统观察器监视计算机上的多个或所有硬盘驱动器,例如。 C:\,D:\,E:\等..
我希望能够监控除CD \ DVD之外的所有驱动器及其子文件夹如果它们没有准备好或没有插入磁盘就会驱动。
我在网上找到了一些例子,但它们只是因为它们的解释不完整而令人困惑检测所有硬盘驱动器,然后将路径分配给文件系统观察程序的多个实例,以便监视整个计算机,而不是一次只监视一个目录。
提前谢谢!!
Hey there I am puzzled as how to go about''s monitoring multiple or all hard drives on my computer with filesystem watcher eg. C:\, D:\, E:\ ect..
I wish to be able to monitor all drives and their subfolders excluding CD\DVD drives if they are not ready or no disk is inserted.
I have found some examples online but it has only been confusing as they are not complete in their explanation about how to detect all hard drives and then to assign the paths to multiple instances of the filesystem watcher so that the entire computer is being monitored and not just one directory at a time.
thank you in advance!!
推荐答案
public static WatchInfo {
public static List<fileSystemWatcher> Watchers = new List<fileSystemWatcher>();
}
现在创建实例时,只需将它们添加到列表中,您可以稍后从程序中引用它们。
当然,您还需要为驱动器中的更改设置适当的事件处理程序。
Now when creating the instances, just add them to the list and you can refer them from your program later.
Of course you would need also to set proper event handlers for changes in the drives.
这篇关于文件系统观察程序的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!