4

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.

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
LuckyScooby
  • 81
  • 10
  • Do you have a specific problem? – johnnyRose Oct 20 '15 at 16:47
  • How does that LED help you, really? Which hard drive are you interested in? If its the drive with the O/S then you might as well paste a green button on your toolbar as the O/S drive is pretty much in use non-stop. To get a better feel for the actual activity I recommend you try Process Monitor and look at the file access tab. https://technet.microsoft.com/en-us/sysinternals/bb896645 – Igor Oct 20 '15 at 17:24
  • 1
    @Igor It helps me by indicating the system is performing some disk task.. for instance, when I need to update or install something and it seems to be frozen, that led is the most practical indicator of such any actual activity. – LuckyScooby Oct 20 '15 at 17:38

1 Answers1

4

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.

Rick S
  • 6,476
  • 5
  • 29
  • 43
  • 1
    awesome! I adapted and executed both VB and C#.. they blink perfectly in sync. All I needed were your code snippets! =] – LuckyScooby Oct 20 '15 at 17:40