WS_EX_COMPOSITED - high CPU

自闭症网瘾萝莉.ら 提交于 2019-12-11 04:36:42

问题


I am using WS_EX_COMPOSITED style in my application but its running the CPU to 100%, is there way to stop my application drawing for a while and to resume only when i need ? Some people are suggesting to use Sleep's but where exactly in WndProc do i put sleeps ?

Thanks in advance.


回答1:


Don't use Sleep. It is the solution to almost no problems.

It's true that WS_EX_COMPOSITED can hog CPU but mostly on XP in my experience. There is a much less significant performance hit on Vista and up. However, if your app is idle then it won't be repainting. If your CPU is 100% and the app is idle then you are doing something wrong in your WM_PAINT handling. What you describe sounds like an endless loop of paint cycles. If you do things right, that won't happen, even if you use WS_EX_COMPOSITED.

As regards the right way to do double buffering, BeginBufferedPaint is the modern way to do this, on Vista and up.




回答2:


If you sleep the application's thread it will make the application UI unresponsive. It sounds to me like you need to implement your drawing code in its own thread. You can then sleep that thread without affecting the rest of your application, although I recommend using events and WaitForSingleObject/WaitForMultipleObjects calls instead of sleep.



来源:https://stackoverflow.com/questions/10604359/ws-ex-composited-high-cpu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!