Coo*_*.Wu 4 wpf cpu performance
我的 WPF 应用程序在大约 30 分钟后使用了高 CPU 使用率,然后我打破了应用程序以找出哪些代码消耗了高 CPU 使用率,但我什么也没得到。
Visual Studio 2008无法显示当前正在运行的代码,但我在“调用堆栈”面板中找到了这一点:
[在睡眠中,等待,或者加入] mscorlib.dll!System.Threading.WaitHandle.WaitAny(System.Threading.WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) + 0x8f 字节 System.dll!System.Net.TimerThread.ThreadProc() + 0x2f9 字节 mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(对象状态) + 0x66 字节 mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContextexecutionContext,System.Threading.ContextCallback回调,对象状态)+ 0x6f字节 mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 字节
这是什么?CPU使用率高是怎么回事?以及如何降低CPU使用率?
我们使用“WPF 性能分析工具”/Visual Profile 来找出哪些事件占用最多的 CPU 使用率。Tick(TimeManager.Tick()) 占用了应用程序大约 40% 的 CPU 使用率。然后我们一一删除了所有的动画控件,最后我们发现有一个故事板会在大约30分钟后增加CPU使用率。
然后我们改变形式:
calendarStoryboard.Begin(txtMessage, HandoffBehavior.Compose, true);
Run Code Online (Sandbox Code Playgroud)
到
calendarStoryboard.Begin(txtMessage, HandoffBehavior.SnapshotAndReplace, true);
Run Code Online (Sandbox Code Playgroud)
这个问题已得到解决。关于HandoffBehavior的更多信息请参考msdn:
http://msdn.microsoft.com/en-us/library/system.windows.media.animation.handoffbehavior.aspx