关于复杂WPF应用程序的性能问题,如何解决?

时间:2022-09-01 19:16:21

I have my main window at something like 6000 x 6000 px. In that window, I can have a lot of controls (more than 5000) and we can zoom/pan where we want.

我的主窗口有6000 x 6000像素。在那个窗口中,我可以有很多控件(超过5000个),我们可以缩放/平移我们想要的位置。

I added 10 "television screens" controls in my application, and each of them have a refresh rate of 100ms. When I start this, everything crash...

我在我的应用程序中添加了10个“电视屏幕”控件,每个控件的刷新率为100毫秒。当我开始这个时,一切都崩溃了......

10 objects with a refresh rate of 100ms each is too much, WPF cannot draw them at the time. I conclude that WPF is very slow to draw what I have....

每个刷新率为100ms的10个对象太多,WPF当时无法绘制它们。我的结论是WPF绘制的东西很慢......

Everything is drawn in vector, but I tried to add .CacheMode on them and it doesn't work either..

一切都是在矢量中绘制的,但我试图在它们上添加.CacheMode,它也不起作用..

What can I do?

我能做什么?

P.S. My PC is 8 core, 8 GB Ram, 256 Mb video card (nvidia quadro nvs 295) on win7 64bits

附:我的PC是win7 64bits上的8核,8 GB Ram,256 Mb视频卡(nvidia quadro nvs 295)

3 个解决方案

#1


2  

Work on reducing the number of controls in your application. 5K is quite a bit, and I think there is probably a way to reduce that number.

努力减少应用程序中的控件数量。 5K是相当多的,我认为可能有一种方法可以减少这个数字。

For example, use TextBlocks instead of Labels as TextBlocks render as 1 control while Labels render as 3 in 4.0 (I think its more than 3 in older versions)

例如,使用TextBlocks而不是Labels作为TextBlocks渲染为1控件,而Labels渲染为4.0中的3(我认为它在旧版本中超过3)

Also, check and see if you can use UI Virtualization with some of your controls. Something like a ListBox of 100 items can be virtualized to only render 10 of them at a time.

此外,检查并查看是否可以将UI虚拟化与某些控件一起使用。类似于100个项目的ListBox的东西可以虚拟化,一次只渲染10个。

#2


3  

WPF uses software rendering in case you exceed maximum supported resolution of you graphics adapter. Moreover, 5k controls! Incredible. WPF is not a silver bullet for everything you imagine. You need to redesign your app or change technology you're using.

如果您超出图形适配器的最大支持分辨率,WPF将使用软件渲染。而且,5k控制!难以置信。 WPF不是你想象的一切的银弹。您需要重新设计应用程序或更改正在使用的技术。

#3


2  

Take a look at ZoomableCanvas - 1 million items. This is the best example out there of what WPF can do when using every optimisation in the book. I suggest you take that example and run it at the maximum resolution on your monitors. If that fails to perform well, then WPF cannot do this.

看看ZoomableCanvas - 100万件物品。这是WPF在使用本书中的每个优化时可以做的最好的例子。我建议您采用该示例并在监视器上以最大分辨率运行它。如果这不能很好地执行,那么WPF就无法做到这一点。

I was unaware that WPF default to software rendering if the resolution exceeds that of the video card. A good caveat to know about!

我不知道如果分辨率超过视频卡的分辨率,WPF默认为软件渲染。一个很好的警告要知道!

Regarding high performance graphical APIs I second Keiren and say use DirectX (SlimDX provides a managed wrapper) instead.

关于高性能图形API我第二个Keiren并说使用DirectX(SlimDX提供托管包装)。

#1


2  

Work on reducing the number of controls in your application. 5K is quite a bit, and I think there is probably a way to reduce that number.

努力减少应用程序中的控件数量。 5K是相当多的,我认为可能有一种方法可以减少这个数字。

For example, use TextBlocks instead of Labels as TextBlocks render as 1 control while Labels render as 3 in 4.0 (I think its more than 3 in older versions)

例如,使用TextBlocks而不是Labels作为TextBlocks渲染为1控件,而Labels渲染为4.0中的3(我认为它在旧版本中超过3)

Also, check and see if you can use UI Virtualization with some of your controls. Something like a ListBox of 100 items can be virtualized to only render 10 of them at a time.

此外,检查并查看是否可以将UI虚拟化与某些控件一起使用。类似于100个项目的ListBox的东西可以虚拟化,一次只渲染10个。

#2


3  

WPF uses software rendering in case you exceed maximum supported resolution of you graphics adapter. Moreover, 5k controls! Incredible. WPF is not a silver bullet for everything you imagine. You need to redesign your app or change technology you're using.

如果您超出图形适配器的最大支持分辨率,WPF将使用软件渲染。而且,5k控制!难以置信。 WPF不是你想象的一切的银弹。您需要重新设计应用程序或更改正在使用的技术。

#3


2  

Take a look at ZoomableCanvas - 1 million items. This is the best example out there of what WPF can do when using every optimisation in the book. I suggest you take that example and run it at the maximum resolution on your monitors. If that fails to perform well, then WPF cannot do this.

看看ZoomableCanvas - 100万件物品。这是WPF在使用本书中的每个优化时可以做的最好的例子。我建议您采用该示例并在监视器上以最大分辨率运行它。如果这不能很好地执行,那么WPF就无法做到这一点。

I was unaware that WPF default to software rendering if the resolution exceeds that of the video card. A good caveat to know about!

我不知道如果分辨率超过视频卡的分辨率,WPF默认为软件渲染。一个很好的警告要知道!

Regarding high performance graphical APIs I second Keiren and say use DirectX (SlimDX provides a managed wrapper) instead.

关于高性能图形API我第二个Keiren并说使用DirectX(SlimDX提供托管包装)。