BitmapCache forces WPF application to block

Here's the script:

1: our WPF application will start

2: 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 download another application that requires UAC

4: Discard this material

The WPF application is no longer responding, but WPF itself is a problem. All the application logic in all background threads is beautiful, and you can interact with it by pressing alt + f4, etc., but the screen never redraws

Viewpoints:

  • If you enter the debugger at this moment, custom code is not working, all WPF
  • Killing DWM.exe brings application back to life
  • If we select elements of BitmapCache d, it will not block
  • I made another simple sample application that used BitmapCache and it showed no problem.

Help !!

+4
source share
2 answers

After hard work, a colleague finally managed to track this down.

Our application first shows the login window, then closes it and shows the main window. We discovered long ago that if you do this, WPF assumes that the first window (the login window) is the main application window, and therefore it closes when it closes.

To mitigate this, we created a fake off-screen window (which never appears) in front of any other windows. Then WPF assumes that this fake window is the main one - it never closes, so our application can work as desired.

For reference, a fake window looks like this:

 m_mainWindow = new Window { Left = int.MaxValue, Top = int.MaxValue, Width = 1, Height = 1 }; m_mainWindow.ShowInTaskbar = false; 

Everything was OK. Some time later, another developer added code to Show and Hide is a fake window.

The display of the main window was what caused it.


Here is the full text:

A: Create a new WPF application in visual studio

B: Put the following code in your App class in App.xaml.cs

 public partial class App : Application { Window m_mainWindow; public App() { m_mainWindow = new Window { Left = int.MaxValue, Top = int.MaxValue, Width = 1, Height = 1 }; m_mainWindow.ShowInTaskbar = false; // Comment this line out and the problem goes away m_mainWindow.Show(); } } 

C: Put at least one BitmapCached element in your MainWindow.xaml . Here is mine

 <Window x:Class="LockupRepro.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid CacheMode="BitmapCache"> <Button Content="Look a button" /> </Grid> </Window> 
  1. Run this program (I'm on Windows 7) and then press ctrl + alt + del or call the UAC prompt.

You will see that the application closes as described in the question - commenting on m_mainWindow.Show fixes it.

Update:

After some further research, this is not just showing a window, it is a fact that ShowInTaskBar set to false. If we do not install this, then displaying the window no longer causes a problem.

Bizarre!

0
source

The problem seems to be difficult to reproduce. All I can offer is advanced debugging -

  • Make sure your stack trace browser "Shows External Code" (right-click menu in VS on the stack trace). Then find the exact place in the internal components of WPF where your application is stuck.
  • The next step is to download pdb for this build, or much easier - use the .NET Reflector.
  • Lots of thinking and thinking ...
  • ???
  • PROFIT!

    :)

0
source

All Articles