C# WPF abnormal CPU usage for animation
I am developing WPF application and client reports extreamly high CPU usage (90%) (whereas i am unable to repeat that behavior). I have traced bootleneck down to these lines. It is simple glowing animation for small single led control (blinking led). What could be reason for this simple annimation taking up SO huge CPU resources?
<Trigger Property="State">
<Trigger.Value>
<local:开发者_运维百科BlinkingLedStatus>Blinking</local:BlinkingLedStatus>
</Trigger.Value>
<Trigger.EnterActions>
<BeginStoryboard Name="beginStoryBoard">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="glow" Storyboard.TargetProperty="Opacity" AutoReverse="True" From="0.0" To="1.0" Duration="0:0:0.5" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<StopStoryboard BeginStoryboardName="beginStoryBoard"/>
</Trigger.ExitActions>
</Trigger>
Chances are that your client does not have hardware accelleration. Todays (and even yesterdays) graphics cards should be sufficient to render WPF. Tell him to update his graphics drivers. You can also tune your animation a little bit by setting Timeline.DesiredFrameRate="20"
(or lower if it suitable for you) on your StoryBoard.
WPF's animations and effects are computationally intensive. They require hardware acceleration to work smoothly. This means that is needs a decent graphics card to play nicely.
You can check whether your app can use hardware acceleration as described here, and remove the glow effect if it doesn't.
(Or just dumb it down, for example add a simple white rectangle instead of it, or something like that.)
I once wrote a simple application which extensively used all sorts of effects and animation, and it was barely usable on an average machine. I dumbed down the effects, and everything became smooth.
精彩评论