IDLE Time Logical Disk

Alexander Hecht 0 Reputation points
2023-05-09T11:32:20.1466667+00:00

Hi,

does anyone know, how to read the idle time of logical disks in C#?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 83,206 Reputation points
    2023-05-09T15:02:54.6233333+00:00

    You can use Performance Counters

    Something like this :

                   System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
                    EventWaitHandle evt = new ManualResetEvent(false);
                    new Thread(() => MonitorCounter("LogicalDisk", "% Idle Time", "C:", evt)).Start();
    
    
            void MonitorCounter(string sCategory, string sCounter, string sInstance, EventWaitHandle evt)
            {
                using (PerformanceCounter pc = new PerformanceCounter(sCategory, sCounter, sInstance))
                {
                    while (!evt.WaitOne(500, false))
                    {
                        float nValue = pc.NextValue();
                        Console.WriteLine(sCounter + " : {0}", Convert.ToString(Math.Round(nValue, 3)));                    
                    }
                }
            }
    
    0 comments No comments