简体   繁体   English

WPF的高CPU使用率

[英]High CPU usage with WPF

In my WPF project, if I open a window, the cpu usage is about 30%-50%, but when I minimize this window, the cpu usage drops to 1%. 在我的WPF项目中,如果我打开一个窗口,cpu使用率大约是30%-50%,但是当我最小化这个窗口时,cpu使用率下降到1%。 Does somebody know the reason why? 有人知道原因吗? Thanks 谢谢

do you have a lot of bindings (two way) on your screen? 你的屏幕上有很多绑定(双向)吗? This can cause high cpu. 这可能会导致高CPU。 Or a lot of animations? 还是很多动画?

Ultimately you could use the WPF performance suite to monitor what is causing this high CPU load: http://msdn.microsoft.com/en-us/library/aa969767.aspx 最终,您可以使用WPF性能套件来监控导致此高CPU负载的原因: http//msdn.microsoft.com/en-us/library/aa969767.aspx

Good post by Rody, I am just going to add a few things, using an answer instead of a comment because comments have max limit.. Rody的好帖子,我只想添加一些内容,使用答案而不是评论,因为评论有最大限制..

I would recommend also to use Ants Profiler, it has 2 week trial period - more than enough to figure out what's going on. 我建议也使用Ants Profiler,它有2个星期的试用期 - 足以弄清楚发生了什么。 Also if you post some of your code, people here can quickly point out a few things. 此外,如果您发布一些代码,这里的人可以快速指出一些事情。

Like for example, if you have, as Rudy pointed out, ton's of Bindings and Animations, as well as, overly complex controls and control templates. 例如,如果你像Rudy所指出的那样,你可以获得大量的Bindings和Animations,以及过于复杂的控件和控件模板。 Question the unnecessary compositions of Stack panel within a stack panel, within a border...use TextBlocks instead of Labels, or whether you need TextBoxes, if they are read only, use TextBlocks + Border. 在堆栈面板内,边框内对Stack面板的不必要组合进行质询...使用TextBlocks而不是Labels,或者是否需要TextBoxes,如果它们是只读的,请使用TextBlocks + Border。 Are your ItemControl's items too complex? 你的ItemControl的项目太复杂了吗? etc... 等等...

Also, Ants Profiler can show you your "zombie" objects. 此外,Ants Profiler可以向您展示您的“僵尸”对象。 Are you disposing correctly, are you recycling your objects, or creating new complex structures every time (for example, when selecting a new date range for your data to display) then rebind to them. 您是否正确处置,是回收对象,还是每次都创建新的复杂结构(例如,选择要显示的数据的新日期范围),然后重新绑定它们。 If you have data grid cells, does every single one need an expensive something...a popup and extra border.. If you create a border around every cell for some visual effect, re-factor to only have one, and re-position it on the grid. 如果你有数据网格单元格,每一个都需要一个昂贵的东西...一个弹出窗口和额外的边框..如果你围绕每个单元格创建一个边框以获得一些视觉效果,重新分解为只有一个,并重新定位它在网格上。 And the list can go on. 列表可以继续。

Long story short - WPF is a hog: so you might have to trim things down, or/and be more inventive to keep things pretty with less overhead. 长话短说 - WPF很糟糕:所以你可能不得不削减一些东西,或者/并且更具创造性,以更少的开销保持漂亮。

PS don't forget to post some code... PS不要忘记发布一些代码......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM