开发者

Avoid UI locking/freezing when assigning datasource?

I'm using MVP pattern, so I have a View that has almost no logic in it and a Presenter that knows how to react to the user's interactions with the view. Everytime I need to get data from a service or such my code does so asynchronously, the problem I'm having is that lets say I get 10,000 items that need to be databound to a Grid, when I assign those (marshalling them through the UI thread) my UI locks for short periods of time (because of the Grid control/CurrencyManager locking the thread I think)

Does anybody know possible ways to avoid this?

I've tried assigning the data in incremental chunks with a timer, but still ends making the UI freeze random开发者_开发问答ly

Cheers


You need to download the data from the server in chunks on a background thread then append them to a client side collection object. If that collection object implements INotifyCollectionChanged then the grid should update automatically. You can get this with ObservableCollection, or with Bindable Linq which may be a better choice.

The problem you will run into is that you have a grid re-drawing 10,000 items over and over again. This is generally not that good of a solution but it can work if you get a grid with UI Virtualization. For example I use the Telerik GridView control and I have had good results with around 5000 records.

Having tried to answer your question directly, let me give you some advice that may lead you in a better direction. Direct query of 10,000 items over the network isn't going to be blazing fast no matter how cool your grid control is. You may want to consider using a service bus to communicate async to the server and store a copy of the data in a local database. I am working on a project that will use Rhino Service Bus to make a smart client that can work even if the network connection goes down for a short time. The service bus approach to smart client development should make your UI locking pains go away and make your app more stable and resilient to network traffic.


You should use some sort of virtual data mode for your grid. This will remove such kind of problem definitively.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜