I'm dealing with a bug relating to a C# WinForms app that starts up with a splash screen, then closes the splash screen and opens a login form. On some computers everything works fine. On others, the login form appears, but with a flashing title bar, which after a few flashes, loses focus altogether. The cursor is still flashing in the "User name" text box, but the app does not have focus, and when you start typing, nothing happens, which is very annoying for the user.
There seems to be no difference what OS is running (we've tried Windows 7 and Server 2008), and we have been particular not to have any keyboard or mouse input after starting up the app.
Now - does anyone have any idea what could be causing the app to lose focus?
Alternatively, how would you debug this issue? We have been unable to replicate the problem in the Visual Studio debug environment, but that doesn't entirely surprise me because I'd guess it's an issue of how the compiled app interacts with the OS... or am I wrong?
EDIT #1: I thought this was solved by @vinodpthmn, by ensuring that the splash screen is properly closed before the login form appears, but this appears not to have helped. So I created a logger to track all the events and threads, and found the following interesting log entries:
Thread 01 - 2012/03/29 12:51:09.693 - Show splash screen
Thread 01 - 2012/03/29 12:51:20.350 - Splash screen closed
Thread 01 - 2012/03/29 12:51:20.490 - Login Form Activated
Thread 01 - 2012/03/29 12:51:20.522 - Login Form Load
Thread 01 - 2012/03/29 12:51:25.694 - Login Form deactivated
Thread 01 - 2012/03/29 12:51:25.694 - Active form =
Thread 01 - 2012/03/29 12:51:25.694 - Active app =
Those last lines showing the active form and app respectively display Form.ActiveForm
and the currently active app in Windows (code for this here). And they are both empty/null. This is so, even if in the Login form Load I call Activate()
or SetForegroundWindow()
as suggested by @memetolsen. The login form never even receives focus!
Any ideas?
EDIT #2: Well, I just eliminated the splash screen, and now the login form gets focus. Replacing the splash screen reintroduces the bug. But I have put code in to ensure that the splash screen is disposed - not just closed - before I try to open the login form.
Could it make a difference that the splash screen is opened with Application.Run(frmSplash)
?