any animation in WPF makes a request a timer resolution of 1ms, lower than the 15.6ms default by Windows, which causes battery drain while any animation is running. I'm using .net 4.5 and running in Windows 10 but it's also happening in Windows 7 and 8.
This is my code:
<Ellipse x:Name="Dash1" RenderTransformOrigin="0.5,0.5" Height="100" Width="100" StrokeDashArray="10" Stroke="Black">
<Ellipse.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever" Timeline.DesiredFrameRate="30">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="Dash1">
<EasingDoubleKeyFrame KeyTime="0:0:5" Value="360"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Ellipse.Triggers>
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
In order to check the timer resolution requested run the following command in a Command Prompt running as admin and check the results:
powercfg /energy
Is there any way to overcome this issue or any workaround? Thanks.
Update
Sorry for the late reply. The windows timer resolution explanation is, by Microsoft:
The system timer resolution determines how frequently Windows performs two main actions: Update the timer tick count if a full tick has elapsed. Check whether a scheduled timer object has expired.
By default Windows timer resolution is 15.6ms but any program can request to lower it, which cause a big hit impact in battery drain. For instance Chrome and vlc are known by lowering the timer resolution.
Recently I discover that any wpf animation playing lowers the timer resolution to 1ms, due to the internal clock it uses to synchronize the animation (I assume). When the animation stops the timer resolution comes back to its normal value but while playing the cpu consumption increases drastically. And the framerate you set on the animation has no influence on this either.
I was wondering if there was any way to prevent this to happen but I'm afraid this is a known issue in WPF and there's no way to solved it.
At the end I'm using my own programmatically animations with a dispatcher timer, which doesn't affect the timer resolution and surprisingly doesn't consume as much cpu but are not as smooth since they depend on the render thread workload.
You can find more reading about this here:
https://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/