views:

213

answers:

3

WPF Windows-XP SP3

I'm having a problem with a simple WPF animation.

I use the following Xaml code (in XamlPad and also in a WPF project):

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Border Name="MyBorder" BorderThickness="10" BorderBrush="Blue" CornerRadius="10" Background="DarkRed" >
       <Rectangle Name="MyRectangle" Margin="10" StrokeDashArray="2.0,1.0" StrokeThickness="10" RadiusX="10" RadiusY="10" Stroke="Black" StrokeDashOffset="0">
           <Rectangle.Triggers>
               <EventTrigger RoutedEvent="Rectangle.Loaded">
                   <BeginStoryboard>
                       <Storyboard>
                           <DoubleAnimation Storyboard.TargetName="MyRectangle" Storyboard.TargetProperty="StrokeDashOffset" From="0.0" To="3.0" Duration="0:0:1" RepeatBehavior="Forever" Timeline.DesiredFrameRate="30" />
                       </Storyboard>
                   </BeginStoryboard>
               </EventTrigger>
           </Rectangle.Triggers>
       </Rectangle>
    </Border>
</Page>

It has the effect of causing the border to animate around the rectangle. After a fresh reboot of the machine, this animation is nice and smooth. However, I tend to leave my machine on all the time and after a period time elapses (I don't know how long), the animation starts stuttering and becomes choppy.

I thought that it may be memory or resource issues, but after shutting down all other apps and any services that seem unnecessary, the stuttering still continues. However, after a system reboot, the animation is smooth again!

I get the same symptoms in a WPF app or in XamlPad. In the case of the app, it doesn't seem to make any difference whether I run in the debugger or if I run the executable directly.

I applied the patch at this link: http://support.microsoft.com/kb/981741 and I thought that it had taken care of the issue, but it seems not to have.

I have seen some posts that might indicate that using transparency might affect animation, but as you can see, my xaml does not use transparency.

Can anyone give me some suggestions on how to determine what the problem is? Are there any WPF diagnostic tools that might help?

UPDATE: I have checked my video drivers and they are the latest version. (nVidia GeForce 8400 GS)

A: 

I think with WPF you will come across machines that don't render very well. I tried this on my laptop and it was fine.

Steven
A: 

After running your animation for a little over a day, I don't see anything really awful going on, although the memory usage has gone up a little.

What I ended up doing was running your example on XP SP3 in kaxaml, and then did some poor-man's performance checking using perfmon.

If you haven't used perfmon before, just do Run -> perfmon from the start menu. It'll likely come up with a few counters already in the list, but you can click each and delete them if you don't want to monitor those values. I don't think CPU utilization in your case is the problem, but you can keep it there just in case.

Right click anywhere and choose "Add Counters", then under "Performance object" select ".NET CLR Memory". On the right, select the executable of interest (in my case, it's "Kaxaml"). On the left side, select "# Bytes in all Heaps". I would also change the sample rate to something larger, like 300 seconds, so you can get a better idea of rate of change over the time period you're experiencing the slowdown.

This might not help you find the slowdown, but it's a reasonable first step. Maybe you should also download the trial of ANTS 5 profiler to see if it catches anything weird.

Dave
Thanks Dave. I don't get the impression that it is just time that causes the issue. I think it must be a combination of factors. I am accepting this answer because of the tips for checking performance.
Chris Dunaway
A: 

I've let the animation run for well over 30 hours and it hasn't slowed down or gotten choppy, but I'm running Win 7. I let it run in an XP VM for several hours too and it runs fine.

My best guess: Video Driver

Justification: The video driver is the most complex driver in your system and has a lot to do with the overall performance of your computer. While it's possible that the animation dispatch timer is getting behind, unless you're using a lot of CPU it's unlikely.

Suggestions:

  • Check for a driver update
  • Try a different video card (if possible)
  • Crack open PerfMon and grab every WPF & DirectX counter possible and monitor over time
Nate Zaugg