I have a windows forms application written in vb.net. I have a form called SplashScreen which is set as the Splash screen in the project properties. The Startup form is set to a form called Logon. I have a user who got an exception when running my app. It occurred right after the splash screen displayed and right before the logon screen displays. The user tried again and hasn't gotten the error again. However, if anyone has any ideas what could be causing this so I can make sure it's fixed, I'd appreciate it.
When googling this error, it seems that it may be related to threading, but I don't do anything special on my logon screen accept use a Me.Activate(). I was having trouble with the logon screen not having focus after the splash screen disappeared and found some forum that said Me.Activate() would fix it, and it has.
Private Sub Logon_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Activate()
End Sub
Here is the error message:
Message: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
Exception: System.InvalidOperationException: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
at System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.HideSplashScreen()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.MainFormLoadingDone(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Stack Trace: at System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.HideSplashScreen()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.MainFormLoadingDone(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Does anyone have any ideas what would cause this?
**** UPDATE ****
One of my users continues to get this error randomly. Just like before, he'll try to run the app, get the error, then try to run the app again a few seconds later and it works just fine. I tried moving the Me.Activate() code to the Logon_Shown event. The user still gets the error every once and a while. Then tried removing the Me.Activate() entirely. The user STILL gets the error. It seems to happen when I publish a new version of the application and the user tries to run it for the first time. But it has also happened randomly at other times. Possibly after the user has rebooted, but not every time he reboots. He uses a machine that runs Windows 7, has admin authority, and has the UAC stuff on but not at it's highest level. It's happened enough with this user that I'm concerned I need to change something or fix something, but again...I have no idea where to start. It appears to be an issue with the built in splash screen feature. If anyone has any new suggestions, I would appreciate any ideas.