WPF画布性能 - children.add调用多次 [英] WPF canvas performance- children.add called many times

查看:2152
本文介绍了WPF画布性能 - children.add调用多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我画了很多线在很长的画布(想想带状图)并将它调整得相当好性能,采用了低级别的几何类和冻结他们,等这个改进的性能大幅提升,但它仍然需要几秒钟加载几千项到画布。我跑的应用程序中的性能分析,它看起来像时的大比例采取的是每次调用 canvas.children.add()。我读过这应该是一个轻量级的号召,因为我称它无数次的一种方法,它不应该尝试做任何重物其间......难道还有可能是这可能是服用其它原因这么多的时间?而什么办法,我可能会加快步伐?

I'm drawing a lot of lines on a long canvas (think stripchart) and have it tuned fairly well for performance, using the low-level geometry classes and freezing them, etc. This improved performance dramatically, but it still takes a few seconds to load a few thousand items into the canvas. I ran a performance analysis on the application, and it looks like a big percentage of the time is taken by each call to canvas.children.add(). I've read that this should be a lightweight call, and since I'm calling it numerous times in one method, it shouldn't be trying to do anything heavy inbetween... Could there possibly be any other reason this might be taking so much time? And any way I might speed it up?

业绩并不可怕,但我担心它可能成为更大的问题后,当我需要处理更大的数据集。

The performance is not terrible, but I fear it could become more of a problem later when I need to deal with larger sets of data.

仅供参考,它看起来像它被称为这个样本中1400倍,它采取的CPU时间接近3秒的现代化/快的笔记本电脑。

Just for reference, it looks like it is called 1400 times in this sample, and it taking almost 3 seconds of CPU time on a modern/fast laptop.

画布是包含在其他控件的层次结构的,所以我很好奇,如果他们可能是导致此。

The canvas is contained in a hierachy of other controls though, so I'm curious if they might be contributing to this.

特注:我也没有设置在画布上一个特定的高度,因为它被设置为填补电网父容器。难道这是问题的来源?

Extra note: I'm also not setting a specific height on the canvas, as it is set to fill the grid parent container. Could this be a source of the problems?

推荐答案

主要问题是Children.Add始终是一个缓慢的操作,即使您使用StreamGeometry对象。最近,我遇到了同样的问题,总结了以下: 如果你把一堆物体到一个新的画布,其嵌套到主画布上,增加操作的性能将得到大幅提升。 而不是增加1400元所以,摆在7油画200成份和7画布添加到主画布上。 由于所有对象现在分属不同的画布,你将需要调整您的应用程序了一点,但是这将是比移动像DrawingVisual一个替代解决方案。

Main problem is that Children.Add is always a slow operation, even if you use StreamGeometry objects. I faced the same problem recently and concluded the following: If you put a bunch of objects into a new canvas and nest it into the main canvas, the performance of the addition operation will be increased dramatically. So, instead of adding 1400 elements, put 200 elements in 7 canvases and add those 7 canvases to the main canvas. Since all objects now belong to different canvases, you will need to adjust your app a bit, but this would be a less drastical solution than moving to an alternative solution like DrawingVisual

这篇关于WPF画布性能 - children.add调用多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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