如何加速 WPF 程序? [英] How to speed up WPF programs?

查看:51
本文介绍了如何加速 WPF 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用和为 Windows Presentation Framework 编程.我主要使用 WPF 和 XAML 编写类似浏览器的应用程序.

但真正让我烦恼的是 WPF 的缓慢.一个只有几个控件的简单页面加载速度足够快,但是一旦页面变得稍微复杂一点,比如包含大量数据输入字段、一两个选项卡控件等,它就会变得很痛苦.

加载此类页面可能需要一秒钟以上的时间.确实是几秒钟,尤其是在速度不那么快的计算机(阅读:客户计算机)上,这可能需要很长时间.

与更改页面上的值相同.WPF UI 的一切都有些呆滞.

这太刻薄了!他们给了我这个漂亮的框架,但让它变得如此缓慢,所以我不得不一直向我们的客户道歉!

我的问题:

  1. 你如何加速 WPF?
  2. 您如何分析瓶颈?
  3. 您如何应对缓慢的问题?

由于这似乎是 WPF 的普遍问题,我正在寻找一般建议,对许多情况和问题都有用.

其他一些相关问题:

解决方案

  1. 你如何加速 WPF?

    通常在使用以下分析工具之一后,很明显是什么导致了我的瓶颈.

    • 如果内存是问题,那么我会虚拟化我的数据.
    • 如果渲染时间是问题,那么我会尽可能虚拟化控件或简化控件模板.
    • 如果处理时间是问题,我会尝试改进我的算法或将该工作移至后台线程,并在工作进行时在我的用户界面中显示抖动.

  2. 您如何分析瓶颈?

  3. 您如何应对缓慢的问题?

    分析和咨询.

I love programming with and for Windows Presentation Framework. Mostly I write browser-like apps using WPF and XAML.

But what really annoys me is the slowness of WPF. A simple page with only a few controls loads fast enough, but as soon as a page is a teeny weeny bit more complex, like containing a lot of data entry fields, one or two tab controls, and stuff, it gets painful.

Loading of such a page can take more than one second. Seconds, indeed, especially on not so fast computers (read: the customers computers) it can take ages.

Same with changing values on the page. Everything about the WPF UI is somehow sluggy.

This is so mean! They give me this beautiful framework, but make it so excruciatingly slow so I'll have to apologize to our customers all the time!

My Question:

  1. How do you speed up WPF?
  2. How do you profile bottlenecks?
  3. How do you deal with the slowness?

Since this seems to be an universal problem with WPF, I'm looking for general advice, useful for many situations and problems.

Some other related questions:

解决方案

  1. How do you speed up WPF?

    Often after using one of the following profiling tools it is obvious what is causing my bottlenecks.

    • If memory is the issue then I virtualize my data.
    • If render time is the issue then I virtualize the controls or simplify control templates where possible.
    • If processing time is the issue I try to improve my algorithm or move that work to a background thread and show a throbber in my ui while the work is going.

  2. How do you profile bottlenecks?

  3. How do you deal with the slowness?

    Profiling and counseling.

这篇关于如何加速 WPF 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆