如何在 WPF 中测量屏幕渲染时间

发布于 2024-10-27 23:02:17 字数 553 浏览 1 评论 0原文

我正在尝试测量基于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

明天过后 2024-11-03 23:02:17

您是否看过WPF 性能套件?您也许能够查看性能并查明有问题的代码。

Did you take a look at the WPF Performance suite? You might be able to see the performance and pinpoint problematic code.

乜一 2024-11-03 23:02:17

您可以在控件的 Loaded 事件之后结束计时器,因为该事件发生在渲染完成之后。

You could end the timer after the control's Loaded event since that occurs after the Rendering is complete.

年华零落成诗 2024-11-03 23:02:17

您应该使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文