.net Windows窗体与数据绑定,速度太慢

发布于 2024-08-26 09:12:29 字数 94 浏览 7 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

野侃 2024-09-02 09:12:30

底线 - 您的应用需要有效地“分页数据”。

这意味着,您将需要“延迟加载”数据。 UI应该只加载和显示它需要显示的数据;因此仅在需要时加载附加数据。

由于您没有提供有关您的应用程序和加载的数据的太多信息。

因此,假设您的应用程序获取 10,000,000,01 条记录。

  • 加载表单
  • 例如,如果您的网格每页显示 25 条记录,则使用 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.

  • Load your form
  • If, for instance your grid shows 25 records per page, so use TOP 100 to fetch the top 100 records, and fill in your first page and next four pages.
  • Upon each 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.

感性不性感 2024-09-02 09:12:30

如果不了解更多关于您的应用程序的信息,很难确定,但首先想到的是,如果您的数据集很大,您应该在数据库端进行分页(通过使用行计数限制查询)而不是在数据库端进行分页。应用端。

数据绑定是 .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.

随梦而飞# 2024-09-02 09:12:30

以下是一些建议:

  • 找出您需要携带大量数据的原因。屏幕上显示的大量数据不会带来良好的用户体验。如果这是一个搜索结果或其他结果,请限制您的搜索结果,例如 100 个,并让用户知道还有更多结果,但他们需要更细粒度的搜索条件。
  • 检查以确保您的数据库查询得到了很好的优化和索引,并且您没有带来超出需要的数据。
  • 假设您使用的是 DataGridView,请查看是否利用 虚拟模式有帮助。下面的描述来自 msdn,其中还有一个示例的链接。

    <块引用>

    虚拟模式设计用于非常大的数据存储。当 VirtualMode 属性为 true 时,您将创建一个具有设定行数和列数的 DataGridView,然后处理 CellValueNeeded 事件来填充单元格。

如果您正在使用其他控件,您可以查看该控件是否提供类似的功能。 ListView也有VirtualMode。

  • 启动 SQL 探查器以查看您的应用程序需要从数据库中获得什么。您可能会看到一些不必要的调用、削减数据需求和延迟加载的机会。还可以调试和分析您的应用程序,以了解您将大部分时间花在哪里。

Here are some recommendations:

  • Find out why you need to bring a large set of data. That much data displayed on the screen will not lead to a good user experience. If this is a search result or something, limit your search results, say 100, and let the user know that there is more but they need a more fine grained search criteria.
  • Check to make sure that your database query is well optimized and indexed and you are not bringing more data than you need to.
  • Assuming you are using a DataGridView, see if taking advantage of VirtualMode helps. Below description is from msdn and there is also a link to an example in there.

    Virtual mode is designed for use with very large stores of data. When the VirtualMode property is true, you create a DataGridView with a set number of rows and columns and then handle the CellValueNeeded event to populate the cells.

If you are using some other control, you can see if that control provides a similar feature. ListView also has VirtualMode.

  • Fire up the SQL profiler to see what your applications is needing from the database. You may see some unnecessary calls, opportunities to trim your data needs and lazy load. Also debug and profile your application to see where you spend most of your time.
末が日狂欢 2024-09-02 09:12:30

如果您使用的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文