开发者

Creating Events for hard disk read and write

I am trying to write something that will fire an event anytime the hard disk reads data or writes data. I know this involves using System.Diagnostics.PerformanceCounter but I don't know this well enough to be able 开发者_JAVA技巧to do this on my own. Can someone point me in the right direction? Also, I'd like the event that fires to return which drive is being read or written to. Any help would be appreciated. This is C#, by the way.


The following does not create events but you could use it together with a timer to display information in the tray (as per comments):

using System.Diagnostics;

private PerformanceCounter diskRead = new PerformanceCounter();
private PerformanceCounter diskWrite = new PerformanceCounter();

diskRead.CategoryName = "PhysicalDisk";
diskRead.CounterName = "Disk Reads/sec";
diskRead.InstanceName = "_Total";

diskWrite.CategoryName = "PhysicalDisk";
diskWrite.CounterName = "Disk Writes/sec";
diskWrite.InstanceName = "_Total";

_Total is for ALL disks... to get the specific instancenames of available disks use:

var cat = new System.Diagnostics.PerformanceCounterCategory("PhysicalDisk");
var instNames = cat.GetInstanceNames();

you can then create a pair of diskRead/diskWrite for every instance you are interested in... for sample on how to use this in combination with a timer see this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜