Reduce frame rate for WPF animations to gain performance


Animations are very cool, but they can cause a high CPU load. One reason could be a missing hardware acceleration due to a old graphics adapter or a software rendering constraint. Another reason could be the the high frame rate of animations that is set to 60 fps by default.

You can easily lower the framerate for all animations by overriding the DesiredFrameRate property of the timeline. Just add the following code to your project and play around with the setting to find a good tradeoff between performance and aesthetic.

   new FrameworkPropertyMetadata { DefaultValue = 30 });

Or you can set the framerate individually for each animation in XAML, using the following code:

    Duration="0:0:0.5" From="1.0" To="0.5"
    Timeline.DesiredFrameRate="30" />

In my current project we have a WPF application that is executed through Citrix. The frame rate has not been an issue until the application was run on a thin client/terminal with extremely limited resources and the application took 100% CPU when running the simplest animation. Our LOB WPF application does not have many animations but the once that are there are needed, so removing animations was out of the question. But we really don’t need 60 fps! So lowering frame rate to 15 made CPU performance go from 100% to 10% when animations was executed, and they all looked the same. Nice feature to know about!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: