Extra NotifyIcon shown in system tray

Posted by Kettch19 on Stack Overflow See other posts from Stack Overflow or by Kettch19
Published on 2011-01-07T16:45:50Z Indexed on 2011/01/07 16:54 UTC
Read the original article Hit count: 191

Filed under:
|
|

I'm having an issue with an app where my NotifyIcon displays an extra icon. The steps to reproduce it are easy, but the problem is that the extra icon shows up after any of the actual codebehind we've added fires. Put simply, clicking a button triggers execution of method FooBar() which runs all the way through fine but its primary duty is to fire a backgroundworker to log into another of our apps. It only appears if this particular button is clicked.

Strangely enough, we have a WndProc method override and if I step through until the extra NotifyIcon appears, it always appears during this method so something else beyond the codebehind must be triggering the behavior. Our WndProc method is currently (although I don't think it's caused by the WndProc):

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

    'Check for WM_COPYDATA message from other app or drag/drop action and handle message
    If m.Msg = NativeMethods.WM_COPYDATA Then
      ' get the standard message structure from lparam
      Dim CD As NativeMethods.COPYDATASTRUCT = m.GetLParam(GetType(NativeMethods.COPYDATASTRUCT))

      'setup byte array
      Dim B(CD.cbData) As Byte

      'copy data from memory into array
      Runtime.InteropServices.Marshal.Copy(New IntPtr(CD.lpData), B, 0, CD.cbData)

      'Get message as string and process
      ProcessWMCopyData(System.Text.Encoding.Default.GetString(B))

      'empty array
      Erase B

      'set message result to 'true', meaning message handled
      m.Result = New IntPtr(1)
    End If

    'pass on result and all messages not handled by this app
    MyBase.WndProc(m)
  End Sub

The only place in the code where the NotifyIcon in question is manipulated at all is in the following event handler (again, don't think this is the culprit, but just for more info):

Private Sub TrayIcon_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TrayIcon.MouseDoubleClick
    If Me.Visible Then
      Me.Hide()
    Else
      PositionBottomRight()
      Me.Show()
    End If
  End Sub

The backgroundworker's DoWork is as follows (just a class call to log in to our other app, but again just for info):

Private Sub LoginBackgroundWorker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles LoginBackgroundWorker.DoWork
    Settings.IsLoggedIn = _wdService.LogOn(Settings.UserName, Settings.Password)
End Sub

Does anyone else have ideas on what might be causing this or how to possibly further debug this? I've been banging my head on this without seeing a pattern so another set of eyes would be extremely appreciated. :) I've posted this on MSDN winforms forums as well and have had no luck there so far either.

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about winforms