Fill DS in thread

W

wackyphill

I have a long running query. I want the results in a DataGrid. I'd like
the grid and form to be responsive and fill up w/ rows as the result
set is read into a dataset that is the datasource of the grid.

Possible?
If so, how should the thread handle updating the grid's datasource and
have the grid reflect the changes w/o waiting till the thread finishes?

Any example would be greatly appreciated.
Thanks.
 
D

Dmytro Lapshyn [MVP]

Hi,

In this case, you will most likely need to fill the DataSet manually from a
DataReader. Do this filling on the worker thread, and invoke an Update
method on the UI thread periodically by using Control.Invoke(). The Update
method will be re-binding the grid to the updated datasource. You must also
ensure that the datasource does not raise any events itself when it is being
modified on the worker thread. Otherwise, the grid might try to act upon
these events, and as soon as they are being raised on a non-UI thread, you
might get a nasty exception.
 
W

wackyphill

Would that cause the position in the Grid to be reset everytime the
datasource was updated? I'd like to avoid that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top