Creating events for reading and writing to the hard drive

I am trying to write something that will fire an event at any time when the hard drive is reading data or writing data. I know that this is due to the use of System.Diagnostics.PerformanceCounter, but I do not know this well enough to be able to do this on my own. Can someone point me in the right direction? In addition, I would like the event that triggers this disk to read or write. Any help would be greatly appreciated. By the way, this is C #.

+5
source share
1 answer

The following events are not generated, but you can use it together with a timer to display information in the tray (in accordance with the 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 for ALL disks ... for specific names of available disks:

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

you can create a pair diskRead/ diskWritefor each instance of interest to you ... for an example of how to use this in combination with a timer, see this .

+8
source

All Articles