I have a WPF application where a lot of time is spent updating a control on the UI(开发者_StackOverflowa data visualization control which causes the app to freeze when the data being added for visualization is fairly large). I cannot use a background thread and call the dispatcher because the data that is being added to the visualizer has to be owned by the UI thread(i.e., datapoints in the visualizer). And I dont like that the UI freezes for so long. What are my options here?
I would suggest profiling the application first to find the bottleneck. I bet this will narrow down your problem.
If it's setup correctly (in the WPF way), it probably accepts some ViewModel class as a datasource. If you change values on that one by one, it might update the GUI each time, that is very expensive. Check if there's a SuspendLayout /ResumeLayout method or something. Or see what happens if you create a new Viewmodel (or deep clone the existing one), write everything to that and then set the DataSource to it.
I don't know what control you're using, but an example from the Winforms DataGridView. There are two ways to add rows manually: call AddRow to add one row at a time, and AddRows to add a bunch of rows in one go and then write to them. AddRows is orders of magnitude faster than AddRow. Read the manual on your control.
GJ
精彩评论