|
|
Title | Monitor CPU usage in Visual Basic .NET |
Description | This example shows how to monitor CPU usage in Visual Basic .NET. |
Keywords | CPU usage, CPU load, PerformanceCounter, VB.NET |
Categories | VB.NET, Windows, Software Engineering |
|
|
This program creates a PerformanceCounter to get total processor time values. When its Timer fires, it adds a new CPU usage value to a ListBox.
|
|
Private m_PerformanceCounter As New _
System.Diagnostics.PerformanceCounter( _
"Processor", "% Processor Time", "_Total")
Private Sub btnClear_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnClear.Click
lstCpu.Items.Clear()
End Sub
Private Sub tmrCheckCpu_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles tmrCheckCpu.Tick
lstCpu.Items.Add(CInt(m_PerformanceCounter.NextValue()) _
& "%")
lstCpu.SelectedIndex = lstCpu.Items.Count - 1
End Sub
|
|
|
|
|
|