Vb.net 如何获得CPU使用率?

Vb.net 如何获得CPU使用率?,vb.net,Vb.net,如何获取要显示在表单标签中的cpu使用率百分比?查看此处: 翻译成VB.Net应该很容易您至少可以在.Net中使用WMI API来完成。WMI允许您获取大量Windows管理类型数据,如CPU使用率、硬件规格等 代码改善说: Import Namespace System.Diagnostics Dim cpu as New PerformanceCounter() With cpu .CategoryName = "Processor" .CounterName = "% P

如何获取要显示在表单标签中的cpu使用率百分比?

查看此处:


翻译成VB.Net应该很容易

您至少可以在.Net中使用WMI API来完成。WMI允许您获取大量Windows管理类型数据,如CPU使用率、硬件规格等

代码改善说:

Import Namespace System.Diagnostics

Dim cpu as New PerformanceCounter()
With cpu
    .CategoryName = "Processor"
    .CounterName = "% Processor Time"
    .InstanceName = "_Total"
End With

myLabel.Text = cpu.NextValue()
如果最终结果为“0”(可能是因为您刚刚创建了PerformanceCounter,然后直接使用它) 您需要添加两行,因为PerformanceCounter需要一些时间来工作:

System.Threading.Thread.Sleep(1000)
myLabel.Text= cpu.NextValue
为了避免这种睡眠,您可能希望在类中声明PerformanceCounter,而不是在子/函数中声明PerformanceCounter,并在forms loading事件中设置问题

System.Threading.Thread.Sleep(1000)
myLabel.Text= cpu.NextValue