WPF 断断续续的动画
WPF Windows-XP SP3
我在处理简单的 WPF 动画时遇到问题。
我使用以下 Xaml 代码(在 XamlPad 和 WPF 项目中):
<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>
它具有使边框围绕矩形进行动画处理的效果。机器重新启动后,动画效果非常流畅。然而,我倾向于让我的机器一直开着,经过一段时间(我不知道多长时间)后,动画开始结巴并变得断断续续。
我认为这可能是内存或资源问题,但在关闭所有其他应用程序和任何看似不必要的服务后,口吃仍然继续。然而,系统重新启动后,动画又恢复流畅了!
我在 WPF 应用程序或 XamlPad 中遇到相同的症状。就应用程序而言,无论是在调试器中运行还是直接运行可执行文件似乎都没有任何区别。
我通过以下链接应用了补丁:http://support.microsoft.com/kb/981741我以为它已经解决了这个问题,但似乎没有。
我看到一些帖子可能表明使用透明度可能会影响动画,但正如您所看到的,我的 xaml 不使用透明度。
谁能给我一些关于如何确定问题所在的建议?是否有任何可能有帮助的 WPF 诊断工具?
更新:我检查了我的视频驱动程序,它们是最新版本。 (nVidia GeForce 8400 GS)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
运行动画一天多一点后,我没有看到任何真正可怕的事情发生,尽管内存使用量增加了一点。
我最终做的是在 kaxaml 中的 XP SP3 上运行您的示例,然后使用 perfmon 进行一些穷人的性能检查。
如果您之前没有使用过 perfmon,只需执行 Run ->;从开始菜单执行 perfmon。它可能会在列表中出现一些计数器,但如果您不想监视这些值,则可以单击每个计数器并将其删除。我认为您的情况下的 CPU 利用率不是问题,但您可以将其保留在那里以防万一。
右键单击任意位置并选择“添加计数器”,然后在“性能对象”下选择“.NET CLR 内存”。在右侧,选择感兴趣的可执行文件(在我的例子中,它是“Kaxaml”)。在左侧,选择“所有堆中的# 字节”。我还将采样率更改为更大的值,例如 300 秒,这样您就可以更好地了解在经历减速期间的变化率。
这可能无法帮助您找到减速的地方,但这是合理的第一步。也许您还应该下载 ANTS 5 分析器的试用版,看看它是否捕获到任何奇怪的东西。
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.
我已经让动画运行了 30 多个小时,并且它没有减慢或变得不稳定,但我运行的是 Win 7。我也让它在 XP 虚拟机中运行了几个小时,并且运行良好。
我的最佳猜测:视频驱动程序
理由:视频驱动程序是系统中最复杂的驱动程序,与计算机的整体性能有很大关系。虽然动画调度计时器可能会落后,但除非您使用大量 CPU,否则这种情况不太可能发生。
建议:
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:
我认为使用 WPF 您会遇到渲染效果不佳的机器。我在我的笔记本电脑上尝试过这个,效果很好。
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.
您是否打开了互联网浏览器?我在运行的动画上也遇到了类似的问题,它断断续续……没什么可怕的,只是引人注目和烦人,就像每半秒左右就会出现微口吃一样……
凭直觉,我关闭了谷歌我打开了 Chrome,口吃问题完全解决了。如果您在运行时打开了任何网络浏览器,请尝试将其关闭,看看是否有帮助,这对我有用。
Do you have any internet browsers open? I had a similar issue on an animation I was running where it was choppy...nothing really terrible it was just noticeable and annoying, like it was micro-stuttering every half second or so...
On a hunch I closed out of Google Chrome that I had open and the stuttering completely resolved. If you have any web browsers open while running it try closing them out and see if it helps, it worked for me.