Detect if hard disk is being accessed or not

冷暖自知 提交于 2019-12-10 23:30:19

问题


I am trying to make a very simple hard disk access monitor to work like those embedded LEDs that blink according to drive usage. That LED REALLY helps me, but the laptop I am using does not have it. =[

So, I've made a simple tray icon application, but I don't know how to determine that variable of disk access.

I've searched for it and found something like System.Diagnostics.PerformanceCounter, but I have no idea on using it for my task.

If there is another solution, I'd also appreciate! =] Thanks.

Oh! I almost forgot, it needs to detect ANY and EVERY access to the hard drive.. I've tested an application out there (with the exact same supposed function), but after some tests I could easily realize it was missing some accesses, mainly when you executed a new program.


回答1:


I've found a hard disk activity monitor sample application written in VB.NET. It's fairly simple so you should have no problem converting it to c#.

The idea is to use two Performance Counters, "Disk Read Bytes/sec" and "Disk Write Bytes/sec" for "LogicalDisk"

 ReadCounter = New PerformanceCounter("LogicalDisk", "Disk Read Bytes/sec", "_Total") 
 WriteCounter = New PerformanceCounter("LogicalDisk", "Disk Write Bytes/sec", "_Total") 

And then in your main loop (which needs to be threaded) you call NextValue to determine if there is disk activity.

R = ReadCounter.NextValue 
W = WriteCounter.NextValue 

The full source code is here on Microsoft's site.



来源:https://stackoverflow.com/questions/33242203/detect-if-hard-disk-is-being-accessed-or-not

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