警告是:創建表單時發生錯誤。有關詳細信息,請參閱Exception.InnerException。錯誤是:無法加載計數器名稱數據,因爲從註冊表中讀取了無效索引''。VB.NET警告,CPU應用程序
我的代碼是:
Imports System
Imports System.Management
Imports System.Diagnostics
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Dim cpuLoad As Integer = CDec(PerformanceCounter1.NextValue.ToString())
cpuLoad = 100 - cpuLoad
Label1.Text = cpuLoad.ToString() & "%"
On Error Resume Next
ProgressBar1.Value = cpuLoad.ToString
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Timer1.Start()
Label2.Text = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\SYSTEM\CentralProcessor\0", "ProcessorNameString", Nothing)
label3.text = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\SYSTEM\CentralProcessor\0", "~MHz", Nothing) & " Mhz"
End Sub
End Class
你應該通過啓用[選項嚴格開]開頭(http:// MSDN .microsoft.com/en-us/library/zcd4xwzs.aspx)並更正它向您顯示的錯誤。 – 2014-10-30 20:46:53
...如果您告訴我們您用於「PerformanceCounter1」的參數,這將有所幫助。 – 2014-10-30 20:53:38
[另請參閱](http://stackoverflow.com/a/23727302/1070452) – Plutonix 2014-10-30 21:32:15