WPF Animations and Performance

來源:互聯網
上載者: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 customers with older computers and slower video cards. Everything on the computer ran slower
with our application running; much slower than I would have expected. The performance problems would 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 could see excessive GPU usage when our application was running on this card (up to 70% GPU usage while the application is idle). I could even see consistent
GPU usage on faster video cards (in the 5% range).

  Something was obviously going on in 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 could 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. Many 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.