如何在 WPF 中测量屏幕渲染时间
我正在尝试测量基于 WPF 的应用程序的性能。目前,我们有代码计算将内容添加到 WPF 渲染树所需的时间。此时,控制权返回到我们的程序。问题是WPF在屏幕上显示内容之前仍然存在延迟。对于复杂的渲染树,这可能只需要几秒钟的时间。
您能推荐一种方法来确定 WPF 何时完成屏幕渲染吗?我希望这些测试能够完全自动化,而不是依赖于拿着秒表坐着的人。
[更新]
感谢到目前为止的建议。
我尝试等待 Loaded 和 ContentRendered 事件,但两者都在内容到达屏幕之前触发。
看起来其他人也遇到这个问题。我已经尝试过建议的步骤 http://social. msdn.microsoft.com/Forums/en-US/wpf/thread/693fbedb-efa6-413e-ab66-530c6961d3fb/ 但仍然无法强制我的代码等待渲染完成。
I am attempting to measure the performance for a WPF based application. Currently we have code that times how long it takes to add the content to the WPF render tree. At this point, control is returned to our program. The problem is that there is still a lag before content is displayed on the screen by WPF. For complicated rendering trees, this can be a matter of seconds.
Can you recommend a method to determine when WPF has completed rendering to the screen? I would like these tests to be fully automated and not rely on someone sitting around with a stopwatch.
[update]
Thanks for the suggestions so far.
I have tried waiting for the Loaded and ContentRendered events, but both fire before the content makes it to the screen.
It looks like others are having this issue. I have tried the steps suggested at
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/693fbedb-efa6-413e-ab66-530c6961d3fb/ but still haven't been able force my code to wait for the rendering to complete.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用以下解决方案: http:// www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/
You may use this solution: http://www.japf.fr/2009/10/measure-rendering-time-in-a-wpf-application/
您是否看过WPF 性能套件?您也许能够查看性能并查明有问题的代码。
Did you take a look at the WPF Performance suite? You might be able to see the performance and pinpoint problematic code.
您可以在控件的
Loaded
事件之后结束计时器,因为该事件发生在渲染完成之后。You could end the timer after the control's
Loaded
event since that occurs after the Rendering is complete.您应该使用 Window 的 ContentRendered 事件。
每次出现完整的渲染序列时都会触发此事件,您可以对其进行计时。
You should use the event ContentRendered of Window.
This will fire every time there's a full rendering sequence, and you can time that.