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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
does anyone know, how to read the idle time of logical disks in C#?
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)));
}
}
}