2009-04-28 106 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。