Yet another coding blog covering everything from C#, WPF, SQL, and Silverlight to any other random thought that passes my way…
RSS icon Home icon
  • Quick way to lower CPU usage in heavy WPF animation desktop app

    Posted on April 17th, 2009 biggert 1 comment

    Earlier this week, we ran into an issue where our desktop application (WPF heavy) was attacking our CPU cycles. Upon further investigation, all problems pointed to our lovely progress spinning controls which are powered by looping WPF animations. After some dabbling with replacing the animations with animated GIFs turned out to be more than its worth (and still gobbled a few cycles), we decided to go with a lovely suggestion from the MSDN forums about reducing the frames per second on the WPF animations update.

    The result was this simple little piece of code:

                    Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = 20 });
    

    A small reduction in the visual refresh rate down to 20 FPS (not easily noticeable to the user) resulted in a huge decrease in CPU usage… from over an average of 30% CPU usage down to an average of 5%.

    On a separate note… word to the wise, don’t bind properties directly to UI elements in WPF which internally make database calls… even if you load the items asynchronously, WPF will bind and make the DB calls on the main thread which will block the UI.

     

    1 responses to “Quick way to lower CPU usage in heavy WPF animation desktop app” RSS icon


    Leave a reply