.net Windows窗体与数据绑定,速度太慢
我有一个 Windows 应用程序,其中表单与数据绑定。
由于数据量大,表单加载缓慢。我还以表单形式显示分页以浏览记录。
我怎样才能提高性能?
I have a windows application in which a form is bound with the data.
The form loads slowly because of large data. I am also showing paging in form to navigate through the records.
How can I increase the performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
底线 - 您的应用需要有效地“分页数据”。
这意味着,您将需要“延迟加载”数据。 UI应该只加载和显示它需要显示的数据;因此仅在需要时加载附加数据。
由于您没有提供有关您的应用程序和加载的数据的太多信息。
因此,假设您的应用程序获取 10,000,000,01 条记录。
TOP 100
获取前 100 条记录,并填写第一页和接下来的四页。Next
或连续的“Next”时,您可以访问数据库来获取下一条记录。请注意,您将需要某种机制(ROW_NUMBER
? )来跟踪正在获取的记录、行号等。此 文章确切地讨论了您所追求的和我所指的内容。
Bottom line- your app needs to 'page the data' effectively.
This means, you will need to "lazy load" the data. The UI should only load and display data that it needs to show; therefore load additional data only when needed.
Since you didnt provide much of an information regarding your app and the data that you load.
So, lets assume that your app fetches 10,000,000,01 records.
TOP 100
to fetch the top 100 records, and fill in your first page and next four pages.Next
or consecutive 'Nexts' you can hit database to fetch next records. Note that, you will require some mechanism(ROW_NUMBER
?) to keep track of the records being fetched, row numbers, etc.This article discusses exactly what you are after and I am referring towards.
如果不了解更多关于您的应用程序的信息,很难确定,但首先想到的是,如果您的数据集很大,您应该在数据库端进行分页(通过使用行计数限制查询)而不是在数据库端进行分页。应用端。
数据绑定是 .NET 的一项便利功能,但它带来了严重的性能开销。一般来说,它只适用于处理少于几千行且最多绑定到几十个控件的小型数据集。如果数据集变得非常大,它们会很快造成损失,并且无论进行多少调整都不会提高应用程序的速度。关键是始终限制数据绑定系统在任何给定时间处理的内存量,以便它不会因元处理而使自身过载。
It's hard to say for certain without knowing more about your application, but the immediate thing that comes to mind is that if your dataset is large, you should be doing pagination on the database side (by constraining the query using row counts) rather than on the application side.
Databinding is a convenience feature of .NET, but it comes with a severe performance overhead. In general it's only acceptable for working with small datasets of less than a few thousand rows bound to a couple of dozen controls at most. If the datasets grow very large, they take their toll very quickly and no amount of tweaking will make the application speedy. The key is always to constrain the amount of memory being juggled by the data binding system at any given time so that it doesn't overload itself with the meta-processing.
以下是一些建议:
<块引用>
虚拟模式设计用于非常大的数据存储。当 VirtualMode 属性为 true 时,您将创建一个具有设定行数和列数的 DataGridView,然后处理 CellValueNeeded 事件来填充单元格。
如果您正在使用其他控件,您可以查看该控件是否提供类似的功能。 ListView也有VirtualMode。
Here are some recommendations:
If you are using some other control, you can see if that control provides a similar feature. ListView also has VirtualMode.
如果您使用的是 SQL Server,请使用 Commaon 实施 分页表表达式和 ROW_NUBER()。这将使您从 Sql 服务器获取更少的数据,并且绝对获得更好的性能。
If you are using SQL server, implement paging using the Commaon table Expressions and ROW_NUBER(). This will allow you to get less data from the Sql server and definitely better performance.