当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - 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%. Does somebody know the reason why? Thanks

网友答案:

do you have a lot of bindings (two way) on your screen? This can cause high 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

网友答案:

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..

I would recommend also to use Ants Profiler, it has 2 week trial period - more than enough to figure out what's going on. 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. 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. Are your ItemControl's items too complex? etc...

Also, Ants Profiler can show you your "zombie" objects. 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.

P.S. don't forget to post some code...

分享给朋友:
您可能感兴趣的文章:
随机阅读: