什么类型的应用程序启动得更快:Windows窗体或WPF?

时间:2021-10-27 20:37:32

As far as I know WPF applications should work faster than Windows Forms applications because WPF applications use DirectX for rendering instead of GDI. But what kind of application will start faster: WPF or Windows Forms? Will the start time be roughly the same or will one type of application be considerably faster than the other?

据我所知,WPF应用程序应该比Windows Forms应用程序运行得更快,因为WPF应用程序使用DirectX进行渲染而不是GDI。但什么样的应用程序会更快启动:WPF或Windows Forms?开始时间是大致相同还是一种应用程序会比另一种更快?

I am not targeting any specific operating system.

我没有针对任何特定的操作系统。

3 个解决方案

#1


3  

Just to point out, in my experience the WPF renderer is in fact quite a bit slower than Windows Forms, despite using DirectX. This is because lots of tesselation and layout calculations are done on the CPU side, which effectively cancels out the performance gain of using the GPU.

只是要指出,根据我的经验,尽管使用DirectX,WPF渲染器实际上比Windows Forms慢很多。这是因为在CPU端进行了大量的细分和布局计算,这有效地抵消了使用GPU的性能提升。

Just google around for "WPF Slow" or "WPF Performance" and you'll find horrified developers shocked to learn their time and effort spent converting WinForms to WPF because of spin about GPUs has been wasted, as the result is slower than the original application.

只是谷歌周围的“WPF慢”或“WPF性能”你会发现惊恐的开发人员震惊地了解他们花费时间和精力将WinForms转换为WPF因为关于GPU的旋转被浪费,因为结果比原始应用程序慢。

However ... I will say this. WPF is far superior to WindowsForms in terms of styling, graphical capabilities, developer productivity (databinding), animation, look and feel etc. If performance really is an issue, on certain areas you can optimise. For instance, did you know that you can get an API to write directly to bitmap in WPF (see the WriteableBitmap class) to do GDI-like operations in memory? This is (surprisingly) about 20x faster than the WPF primitives for some operations.

但是......我会说这个。 WPF在样式,图形功能,开发人员生产力(数据绑定),动画,外观和感觉等方面远远优于WindowsForms。如果性能确实存在问题,那么在某些方面您可以进行优化。例如,您是否知道可以获得一个API直接写入WPF中的位图(请参阅WriteableBitmap类)以在内存中执行类似GDI的操作?对于某些操作,这(令人惊讶地)比WPF原语快20倍。

Similarly you can use virtualization to improve the performance of datagrids etc. Telerik have an example of their grid scrolling 1,000,000 rows at interactive framerates.

类似地,您可以使用虚拟化来提高数据网格的性能等.Telerik有一个网格在交互式帧速率下滚动1,000,000行的示例。

In conclusion, have a think about what you are doing and see similar examples on the web. Are you doing real-time scientific dataacquisition and visualization or just a standard line of business app? Comparing similar examples to see what the framework is capable of will help you in your decision.

总之,要考虑一下你在做什么,并在网上看到类似的例子。您是在进行实时科学数据采集和可视化还是只是标准的业务应用程序?比较类似的示例以查看框架的功能将帮助您做出决策。

Update 2013 Q3

更新2013年第3季度

As an update, in various projects I'm now seeing faster and faster performance from WPF by moving anything and everything off the UI thread. E.g. leave the UI thread just for UI, do as much work as possible using Task Parallel Library or RX. Make everything async and don't block the UI thread while waiting.

作为一个更新,在各种项目中,我现在通过从UI线程移动任何东西和所有东西,从WPF看到更快更快的性能。例如。保留UI线程仅用于UI,使用任务并行库或RX做尽可能多的工作。使所有内容都异步,并且在等待时不要阻止UI线程。

Eliminate binding errors as these contribute to WPF performance problems.

消除绑定错误,因为这些会导致WPF性能问题。

You can move animations (e.g. wait or loading animations) onto a different thread for glitch-free animation. You can use render-to-bitmap when doing animated transitions.

您可以将动画(例如,等待或加载动画)移动到不同的线程上,以实现无故障动画。在进行动画过渡时,可以使用渲染到位图。

The long story short? It is possible to get great performance from WPF applications (as well as slick UI) but you need to put in a bit more work!

长话短说?可以从WPF应用程序(以及光滑的UI)获得出色的性能,但您需要投入更多的工作!

#2


2  

I think the start time will be about the same.. I have created a few WPF applications recently and in some cases I think the initial loadtime is a bit slower than win forms, but it is not much and WPF more than makes up for it when the application is up and running

我认为开始时间大致相同..我最近创建了一些WPF应用程序,在某些情况下我认为初始加载时间比win表单慢一点,但它并不多,WPF不仅仅是弥补它当应用程序启动并运行时

#3


0  

From my experience, I think WPF is quite reactive at start compared to winforms. However, the question is tough, especially considering that WPF can contain the other and vice versa.

根据我的经验,我认为与winforms相比,WPF在开始时非常反应。然而,这个问题很难,特别是考虑到WPF可以包含另一个,反之亦然。

I'd follow the philosophy of this article : http://joshsmithonwpf.wordpress.com/2007/09/05/wpf-vs-windows-forms/

我会遵循这篇文章的理念:http://joshsmithonwpf.wordpress.com/2007/09/05/wpf-vs-windows-forms/

WPF and Winforms are just not the same tool, and neither of them is supposed to substitute for the other ;)

WPF和Winforms只是不一样的工具,它们都不应该替代另一个;)

The question has a lot of duplicates on this forum, please check here for a link and discussion and all of them : WPF vs. Windows Forms

这个问题在这个论坛上有很多重复,请点击这里查看链接和讨论以及所有这些:WPF与Windows Forms

#1


3  

Just to point out, in my experience the WPF renderer is in fact quite a bit slower than Windows Forms, despite using DirectX. This is because lots of tesselation and layout calculations are done on the CPU side, which effectively cancels out the performance gain of using the GPU.

只是要指出,根据我的经验,尽管使用DirectX,WPF渲染器实际上比Windows Forms慢很多。这是因为在CPU端进行了大量的细分和布局计算,这有效地抵消了使用GPU的性能提升。

Just google around for "WPF Slow" or "WPF Performance" and you'll find horrified developers shocked to learn their time and effort spent converting WinForms to WPF because of spin about GPUs has been wasted, as the result is slower than the original application.

只是谷歌周围的“WPF慢”或“WPF性能”你会发现惊恐的开发人员震惊地了解他们花费时间和精力将WinForms转换为WPF因为关于GPU的旋转被浪费,因为结果比原始应用程序慢。

However ... I will say this. WPF is far superior to WindowsForms in terms of styling, graphical capabilities, developer productivity (databinding), animation, look and feel etc. If performance really is an issue, on certain areas you can optimise. For instance, did you know that you can get an API to write directly to bitmap in WPF (see the WriteableBitmap class) to do GDI-like operations in memory? This is (surprisingly) about 20x faster than the WPF primitives for some operations.

但是......我会说这个。 WPF在样式,图形功能,开发人员生产力(数据绑定),动画,外观和感觉等方面远远优于WindowsForms。如果性能确实存在问题,那么在某些方面您可以进行优化。例如,您是否知道可以获得一个API直接写入WPF中的位图(请参阅WriteableBitmap类)以在内存中执行类似GDI的操作?对于某些操作,这(令人惊讶地)比WPF原语快20倍。

Similarly you can use virtualization to improve the performance of datagrids etc. Telerik have an example of their grid scrolling 1,000,000 rows at interactive framerates.

类似地,您可以使用虚拟化来提高数据网格的性能等.Telerik有一个网格在交互式帧速率下滚动1,000,000行的示例。

In conclusion, have a think about what you are doing and see similar examples on the web. Are you doing real-time scientific dataacquisition and visualization or just a standard line of business app? Comparing similar examples to see what the framework is capable of will help you in your decision.

总之,要考虑一下你在做什么,并在网上看到类似的例子。您是在进行实时科学数据采集和可视化还是只是标准的业务应用程序?比较类似的示例以查看框架的功能将帮助您做出决策。

Update 2013 Q3

更新2013年第3季度

As an update, in various projects I'm now seeing faster and faster performance from WPF by moving anything and everything off the UI thread. E.g. leave the UI thread just for UI, do as much work as possible using Task Parallel Library or RX. Make everything async and don't block the UI thread while waiting.

作为一个更新,在各种项目中,我现在通过从UI线程移动任何东西和所有东西,从WPF看到更快更快的性能。例如。保留UI线程仅用于UI,使用任务并行库或RX做尽可能多的工作。使所有内容都异步,并且在等待时不要阻止UI线程。

Eliminate binding errors as these contribute to WPF performance problems.

消除绑定错误,因为这些会导致WPF性能问题。

You can move animations (e.g. wait or loading animations) onto a different thread for glitch-free animation. You can use render-to-bitmap when doing animated transitions.

您可以将动画(例如,等待或加载动画)移动到不同的线程上,以实现无故障动画。在进行动画过渡时,可以使用渲染到位图。

The long story short? It is possible to get great performance from WPF applications (as well as slick UI) but you need to put in a bit more work!

长话短说?可以从WPF应用程序(以及光滑的UI)获得出色的性能,但您需要投入更多的工作!

#2


2  

I think the start time will be about the same.. I have created a few WPF applications recently and in some cases I think the initial loadtime is a bit slower than win forms, but it is not much and WPF more than makes up for it when the application is up and running

我认为开始时间大致相同..我最近创建了一些WPF应用程序,在某些情况下我认为初始加载时间比win表单慢一点,但它并不多,WPF不仅仅是弥补它当应用程序启动并运行时

#3


0  

From my experience, I think WPF is quite reactive at start compared to winforms. However, the question is tough, especially considering that WPF can contain the other and vice versa.

根据我的经验,我认为与winforms相比,WPF在开始时非常反应。然而,这个问题很难,特别是考虑到WPF可以包含另一个,反之亦然。

I'd follow the philosophy of this article : http://joshsmithonwpf.wordpress.com/2007/09/05/wpf-vs-windows-forms/

我会遵循这篇文章的理念:http://joshsmithonwpf.wordpress.com/2007/09/05/wpf-vs-windows-forms/

WPF and Winforms are just not the same tool, and neither of them is supposed to substitute for the other ;)

WPF和Winforms只是不一样的工具,它们都不应该替代另一个;)

The question has a lot of duplicates on this forum, please check here for a link and discussion and all of them : WPF vs. Windows Forms

这个问题在这个论坛上有很多重复,请点击这里查看链接和讨论以及所有这些:WPF与Windows Forms