PerformanceCounter cpuload = new PerformanceCounter();
cpuload.CategoryName = "Processor";
cpuload.CounterName = "% Processor Time";
cpuload.InstanceName = "_Total";
Console.WriteLine(cpuload.NextValue() + "%");
Run Code Online (Sandbox Code Playgroud)
输出总是0%,而cpuload.RawValue像是736861484375左右,发生了NextValue()什么?
我需要一种方法来获得当前系统网络的使用,上下.
我在网上找到了一些,但他们没有为我工作.
谢谢你的帮助
代码段:
private void timerPerf_Tick(object sender, EventArgs e)
{
if (!NetworkInterface.GetIsNetworkAvailable())
return;
NetworkInterface[] interfaces
= NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in interfaces)
{
this.labelnetup.Text = " Bytes Sent: " + ni.GetIPv4Statistics().BytesSent;
this.labelnetdown.Text = " Bytes Rec: " + ni.GetIPv4Statistics().BytesReceived;
}
}
Run Code Online (Sandbox Code Playgroud)