Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Temporary Display Freeze

I have a standalone WPF application running on .NET 3.5. Every so often, the display simply freezes up for several seconds. This is most noticeable on screens where something is being updated often. Here is a video showing the problem.

While the display is frozen, the interface remains responsive (video).

I've come across some other posts with similar problems who attributed it to a SW/HW rendering issue. To be safe, I disabled HW rendering altogether, but still have the problem.

I ran a file monitor during the freezes to see if there is some extraordinary file access or activity going on, but nothing is out of the ordinary.

Final note: The target platform is a small touch-screen panel PC without much memory or horsepower (512 MB). I only see this issue on the target, never on my development PC, which has much more in the way of resources.

UPDATE

I thought I had fixed the issue by removing some animation code, but it did not work. I am still encountering the problem and I'm at the end of my rope.

Here's some more things I've tried:

  • Upgraded to .NET 4.0. Same behavior.
  • Added debug code to all methods that may be invoked via DispatcherTimer (which are called on the UI thread) to make sure none of them are holding up the UI.

I'm really stumped here and have added a bounty. As I mentioned, the problem only occurs on the target PC (link).

like image 220
BabaBooey Avatar asked Apr 17 '11 21:04

BabaBooey


3 Answers

I tend to suspect either .NET GC or the OS swapfile when this kind of behavior shows up.

For the former, you could try the .NET performance counters to monitor for suspect activity.

If the device has a swap file, you can disable it and see if the behavior changes.

As others have said, a profiler (or some what of isolating what condition is inducing the delay - even just attaching and breaking the debugger when it occurs) would be a good way to get more information.

like image 72
holtavolt Avatar answered Oct 09 '22 14:10

holtavolt


Did you tried to profile the application on the tested system? Using a memory and/or performance profiler?

You could get some good informations out of this type of test : some .Net profilers And here's one for WPF : WPF profiler from microsoft

like image 35
Drahakar Avatar answered Oct 09 '22 13:10

Drahakar


The culprit was the following method call:

new HwndSource(new HwndSourceParameters());

This was added to my application because it patched a memory leak problem in .NET 3.5. This work-around can be found here. If I remove this call, the rendering issues go away.

I took out the call and fixed the memory leak in another way (removing storyboard animation and using code behind instead)

like image 36
BabaBooey Avatar answered Oct 09 '22 13:10

BabaBooey