WPF animations and Performance

Source: Internet
Author: User

I 've been working on a WPF application that is fully skinned to make everything in the application look custom. WPF makes this really easy... Almost too easy. we 've been adding a lot of animations and
storyboards to make transitions between screens and long running operations look much better. everything worked perfectly, but we were getting some complaints from MERs with older computers and slower video cards. everything on the computer ran slower
with our application running; much slower than I wowould have expected. the performance problems wocould persist even when our application was idle.

A while back, I added a cheap geforce 8400gs to my workstation for my 3rd and 4th monitors so I decided to run our application on it to see if it was slow too. I use evga precision to tweak my video
Cards and it has a GPU usage graph, so I fired up our application and monitored it with evga precision. I cocould see excessive GPU usage when our application was running on this card (up to 70% GPU usage while the application is idle ). I cocould even see consistent
GPU usage on faster video cards (in the 5% range ).

Something was obviusly going on the background. Our application does medical imaging, so my first thought was that we had something running in the background. But, running a profiler on the Application
Showed that our background threads weren't doing anything. What else cocould be going on?

On a whim, I disabled all of our animations. The GPU usage went to 0%. We are obviously doing something wrong with the animations. After some googling, I learned that WPF storyboards and animations
Keep running even when the element being animated is not visible. warning of our recent storyboards were started on the contentcontrol. loaded event and the animations were set to have a repeatbehavior of forever. I changed all of our storyboards to begin when
Needed and to stop when not needed. This change kept our GPU usage at 0% and made our users much happier.

Much of our storyboard and animation XAML code was pulled directly from blog posts and samples found on the Internet. I really learned my lesson this time:

You shall understand your technology before using (and abusing) it.


Source: http://www.robmulcahey.com/blog/2010/11/24/WPFAnimationsAndPerformance.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.