2009-04-28 117 views

回答

19
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

thanx帮助 – Mark 2011-04-11 23:10:16

2

codekaizen说:

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需要一些工作时间,所以需要添加2行:

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

为了避免睡眠,您可能需要在Class中声明PerformanceCounter而不是Sub/Function,并在窗体加载事件中设置probs。