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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With