我几年前写了一个简单的VB应用程序,它使用一个计时器来调用2个PerformanceCounters,一个用于检测磁盘读取,另一个用于磁盘写入。该信息用于相应地更改托盘图标,因此它就像计算机机箱上的HDD LED一样。它已经运行了多年,直到最近它开始抛出一个InvalideOperationException。:
"未处理的类型' System.InvalidOperationException'发生在DriveTray.exe
其他信息:创建表单时出错。有关详细信息,请参阅Exception.InnerException。错误是:输入字符串的格式不正确。"
所有给出的信息。我不知道它意味着什么,也无法找到任何相关的在线帮助。我正在运行Windows 10,最近在更新图标时使用Visual Studio 2015重新编译/重新发布,但它仍然正常工作。此行为仅在最后一两天开始。我重新安装VS思考可能其中一个库以某种方式损坏了,但那并没有起作用。由于我多年来没有改变任何代码,我甚至不知道在哪里看。
这是我的代码:
公共类frmDriveTray
Private Sub Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer.Tick
Dim both As Integer = 0
If (Me.pcLogicalDiskRead.NextValue > 0) Then
both += 1
End If
If (Me.pcLogicalDiskWrite.NextValue > 0) Then
both += 2
End If
Select Case both
Case 0 'no activity
Me.NotifyIcon.Icon = My.Resources.icoCLOUDS
Case 1 'reading
Me.NotifyIcon.Icon = My.Resources.icoGREEN
Case 2 'writing
Me.NotifyIcon.Icon = My.Resources.icoRED
Case 3 'reading and writing
Me.NotifyIcon.Icon = My.Resources.icoAMBER
End Select
End Sub
Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
Me.NotifyIcon.Visible = False
Me.NotifyIcon.Dispose()
Me.Timer.Dispose()
Application.Exit()
End Sub
Private Sub frmDriveTray_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.mnuRunAtStartup.Checked = My.Settings.RunAtStartup
Me.NotifyIcon.Icon = My.Resources.icoIRIDESCENT
Me.NotifyIcon.Visible = True
Me.NotifyIcon.Text = "1.1.0.10"
Me.Hide()
End Sub
Private Sub mnuRunAtStartup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuRunAtStartup.Click
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
If Me.mnuRunAtStartup.Checked = True Then
key.SetValue(Application.ProductName, Application.ExecutablePath)
Else
If key.GetValue(Application.ProductName) Is Nothing Then
key.Close()
Else
key.DeleteValue(Application.ProductName)
End If
End If
My.Settings.RunAtStartup = Me.mnuRunAtStartup.Checked
End Sub
结束班