I have used this code in many of my applications but now it seems to be erroring and I'm not sure what is causing the error. Basically when I click on the NotifyIcon I want o show the form and when its minimized i want to not show up in the taskbar.

VB Code:
  1. Private Sub Main_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
  2.         If Me.WindowState = FormWindowState.Minimized Then
  3.             Me.ShowInTaskbar = False
  4.             NotifyIcon.Visible = True
  5.         Else
  6.            [COLOR=Red] Me.ShowInTaskbar = True 'Error[/COLOR]
  7.             NotifyIcon.Visible = False
  8.         End If
  9.     End Sub

Here is the execption that is getting thrown.
System.ComponentModel.Win32Exception was unhandled ErrorCode=-2147467259 Message="Error creating window handle." Source="System.Windows.Forms"

Any ideas for a solution?

Thanks In Advance