WPF Animations and Performance

  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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值