一个令人毛骨悚然的问题,让我们看看这个人可以获得几张否决票?
private static PerformanceCounter PC18 = new PerformanceCounter("PhysicalDisk", "% Disk Time", "_Total");
使用以下方式致电柜台
private void Timer_Tick(object sender, EventArgs e)
{
Console.WriteLine($"PC18.NextValue()");
}
此计时器设置为1秒间隔。
我得到的值没有相应的磁盘使用率%,正在显示130.02之类的值。
这是我能找到的唯一使用磁盘使用情况的PerformanceCounter。为什么我会得到错误的值?
答案 0 :(得分:0)
Ah ha, the instanceName, '_total' is not the figure on of disk, its all disks.
So, an answer here fixed my problem:
PC18 = new PerformanceCounter("PhysicalDisk", "% Disk Time", "0 C:");
Where: '0 C:' is the Instance Name of my physical disk C:
Thanks to 'Henk Holterman', all though the answer was not entirely clear, it was enough to make towards the final answer. Thanks!
PerformanceCounterCategory Category = new System.Diagnostics.PerformanceCounterCategory("PhysicalDisk");
string[] InstanceNames = Category.GetInstanceNames();
foreach (string Name in InstanceNames)
richTextBox1.AppendText(Name + Environment.NewLine);
That will give you the Instance Names you need.