Here’s the scenario:
1: Our WPF application starts
2: The WPF application loads various user controls, including some that use the new BitmapCache feature in WPF 4
3: Hit ctrl-alt-delete or win+l or load another application which requires UAC
4: Cancel that stuff
The WPF application is now unresponsive, however it’s WPF itself which is the problem. All the application logic on all the background threads is fine, and you can interact with it by pressing alt+f4, etc, but the screen never redraws
Points of note:
- If you break into the debugger at this point there is no user code running, it’s all WPF
- Killing DWM.exe brings the application back to life
- If we take out the
BitmapCached elements, it doesn’t lock up - I made another simple sample application which used BitmapCache, and it didn’t exhibit the problem.
Help!!
After much hard work, a co-worker finally managed to track this down.
Our application initially shows a logon window, then closes it, and shows a main window. We discovered a long time ago that if you do this, WPF assumes that the first window (the logon window) is the application’s main window, and so it shuts down when it closes.
To mitigate this, we created a fake offscreen window (which is never shown) before any other windows. WPF then assumes this fake window is the main one – it never closes, so our app can work as desired.
For reference, the fake window looks like this:
This was all fine. Some time later, another developer added some code to
ShowandHidethis fake window.Showing the main window was what caused it.
Here’s a full repro:
A: Make a new WPF app in visual studio
B: Put the following code in your
Appclass inApp.xaml.csC: Put at least one
BitmapCachedelement in yourMainWindow.xaml. Here’s mineYou’ll see the app appear to lock up as described in the question – commenting out the m_mainWindow.Show fixes it.
Update:
Upon some further investigation it’s not just showing the window, it’s the fact that
ShowInTaskBaris set to false. If we don’t set that, then showing the window no longer causes the issue.Bizarre!