Performance Flowdocument with Table with a big amount of data

[亡魂溺海] 提交于 2020-01-16 01:02:14

问题


What I try to do:
Generate a report based on data from the database, and then be able to view it and print it. (This in WPF C#)

How I do it: (dynamically, via code)
My Window is simple, it's just a FlowDocumentPageViewer with nothing in it.

  1. I load the data from the database
  2. Use LINQ to group it all properly
  3. Initialize a new Flowdocument
  4. Make a Table, with a RowGroup
  5. Loop my LINQed data and fill the RowGroup with TableRows that contain cells with the required data
  6. Add the Table to the Flowdocument

And this pretty much works fine, except when the amount of records goes to 10k. Then for some reason it just sucks up my CPU to 25% and takes 30 minutes. Scrolling is also pretty much impossible, not a thing happens, it just totally jams. But when I got 1k records, it takes 18 seconds. And with 2k, its 74 seconds.

I do however, do not use the standard way of cells in Tables, I have to make a TextBlock for each cell, and use that with a BlockUIContainer. But after some testing it didn't seem to have much of an impact in generating the document.

Anyone with tips on stuff that I should worry about? Would be a major help, I'm hitting a brick wall here.

I thought about maybe a way that it only renders the current page, but I can't know how many pages there will be with a FlowDocument.

The type of data I use is just strings, and sometimes checkboxes (readonly).

Edit:
The time to process it seems very steady, with 1 second as margin. But exponential, with 3k it's already at 164 seconds.

Edit2:
After some more testing, I found out that the problem is when I add a TableCell to the TableRow. Without that, it only takes 1.6 seconds.


回答1:


The reason is the grouping. There is a known performance issue in this feature under wpf. Try remove grouping for test and you will see the increasing performance!



来源:https://stackoverflow.com/questions/7875834/performance-flowdocument-with-table-with-a-big-amount-of-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!