0

I wrote a simple VB app years ago that uses a timer to call 2 PerformanceCounters, one to detect disk reads and the other for disk writes. That information is used to change a tray icon accordingly so it acts like an HDD LED on a computer case. It has worked fabulously for years, until recently it started throwing an InvalideOperationException.:

"An unhandled exception of type 'System.InvalidOperationException' occurred in DriveTray.exe

Additional information: An error occurred creating the form. See Exception.InnerException for details. The error is: Input string was not in a correct format."

That's all the information given. I have no clue what it means, and can't find any online help that's relevant. I'm running Windows 10 and recently recompiled/republished using Visual Studio 2015 when I updated the icons, but it still worked fine. This behavior has started only in the last day or two. I reinstalled VS thinking maybe one of the libraries got corrupted somehow, but that didn't work. Since I haven't changed any of the code for years, I don't even know where to look.

Here's my code:

Public Class 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

End Class

Rev3d
  • 1
  • 3
  • The exception contains a call stack. The call stack tells you where in the application the exception was thrown. Without that, it takes much more work to try and help you. Which is probably why nobody has :/ –  Sep 09 '16 at 19:23
  • Thanks for the post, Will. Actually, I discovered that this app was running fine on other computers that I had updated to Windows 10; it was only on one computer that the problem occurred. So, I did a System Restore on that computer, and that fixed the problem, whatever it was. – Rev3d Sep 10 '16 at 15:32

0 Answers0