tags:

views:

167

answers:

4

Hi guys,

I have a form with two panels(top, bottom), each panel contains grids. Basically, it's a Master-Detail form where selecting a row from the top grid would show details in the bottom grid.

Binding the data to the detail grid is taking some time. Since binding is done on UI thread, it blocks the thread and therefore the user cannot select another row from the master grid until the binding is done.

Please note that by binding I don't mean getting data from data source. It's the actual binding that's taking longer as it does a lot of data massaging. How can I keep the UI thread free while the detail grid is doing it's binding?

Thanks a million.

+1  A: 

You can't. The update of the UI has to be performed on the UI thread.

You may be able to speed up the binding by using things such as BeginUpdate/EndUpdate which is available on some controls but as you don't specify what you are using I can't say if that's available.

Garry Shutler
Garry, It's Infragistics grid
Sheraz
And I"m already calling BeginUpdate and EndUpdate
Sheraz
A: 

You can use a background thread to perform your data retrieval, then use the UI thread to display it.

ck
I got the impression he was already doing this
Garry Shutler
ck: as I said, the delay is not fetching data but binding data to grid and therefore BackGround thread is of no use.
Sheraz
Then you are either binding far too much data, or have a very slow machine :)
ck
A: 

If I were you, it sounds like you are dealing with a LOT of data, and I would separate all the "massaging" you can into a separate thread process.

So maybe for example when a master record is created, you "manually" spin off the detail data in a background thread to another dataset and do the massaging, then just bind the resulting dataset to the grid. That way the only thing taking place on the UI thread is just the UI binding.

Ultimately if it's taking that long, you may be approaching a critical point in your application where you need to manually do what you need to do in code rather than using the out of the box data binding features in .NET.

routeNpingme
routeNpingme:You said "hat way the only thing taking place on the UI thread is just the UI binding". My question was basically pointing out the problem that the dalay is when I'm binding not when I'm getting data.
Sheraz
My comment originated from where you said you were massaging the data - assumably this is happening in some form of _DataBinding event? Or am I mistaken?
routeNpingme
Basically grid has to format the data (numbers, currencies etc) and when we bind the data, it does all that. As soon as I set the source to grid (grid.DataSource = value), it holds the thread for 2-3 seconds. During this period the screen is frozen. Hope that I explained in detail this time.Thanks
Sheraz
A: 

Finally I found the solution. The solution doesn't include multithreading to start with. As I said that the delay was in binding the grid meaning the main thread was held, we couldn't do much. So the solution is to bring delays. When user selects the master row, a timer ticks off for a certain time. If another request is made before the time is expired, timer gets restarted. This is we ignore all calls that are made because user was clicking or selecting rows too fast. Once timer is expired, I take the selected row and display data. Simple and elegant solution.

Sheraz