We ran into a strange problem while our Infovark application was starting up. If we displayed a modal dialog prior to our main window, it would appear briefly on the screen, then vanish. The user wouldn’t have any time to click any buttons, much less actually read the message on the dialog.
We’d been using modal dialogs in our startup routine for several purposes. We’d display an error message if certain application prerequisites hadn’t been met. We might inform the user that the system was performing an upgrade. Or, most important, we might show our trial/evaluation dialog. This last message tells the user how many days were remaining in the evaluation period, and provides a way for the user to visit our website and buy a copy. (Critical functionality for us!)
All of these messages had been working properly in our integration tests. And then one day they stopped working.
After looking through our check-in logs and hunting around online, we discovered that the problem had to do with the WPF Splash Screen mechanism. We’d followed the instructions in How To Add a Splash Screen to a WPF Application and added a static image to our project to display to the user while the application was loading.
But apparently, this has a nasty side effect of clobbering any modal dialogs that you show before your first non-modal window. A few other folks have noted the same problem. It’s been submitted twice on Microsoft Connect as a bug:
But it’s not clear whether Microsoft’s going to address the issue. The cause of the problem is that a modal dialog without an explicit parent window set will automatically attach itself to an active non-modal window. It’s a nifty behavior in most cases, but if a modal dialog attaches itself to a splash screen, and the splash screen is dismissed — well, so is your dialog!
So, what are our options? One is to avoid Visual Studio’s built-in splash screen feature entirely and create our own splash screen. This thread in the MSDN forums describes how that can be done.
That seemed like too much work for us, which left us with three possible workarounds:
I don’t recommend that last technique — though it does work — so I’m not going to provide a link to it.
I found several custom implementations of splash screens on CodePlex, but at this stage, so close to our 2.0 release, I didn’t want to add any code to our project that I didn’t thoroughly understand.
Since our software licensing code come from a third party, we couldn’t easily modify all of the windows shown during start-up to be non-modal.
So ultimately we decided to use the hidden window workaround. It seemed the quickest way to get the behavior we wanted. It feels a bit dirty, but I can’t justify rolling my own splash screen implementation just to display a static “Loading…” image.
I’d really like to see Microsoft fix this one. If you think so too, vote for the issue here. Thanks!