im using a background worker to fill a dataset from a sql query and setting the datasource of the ultragrid to that dataset. i sometimes get an object not set to an instance error while doing this and i think it must do with setting the grid datasource. i saw the help here : http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.Aspx?ArticleID=9838
but i am not using a collection as in the example. im not sure if i should be setting the datasource on the background thread or if i should fill the dataset on the background worker, and use the UI thread to bind the grid to the dataset. any help i would really appreciate. thanks
roryap said:I don't understand about your response is that it seems to defeat the purpose of using the background worker in the first place
You are correct, it does.
Basically, there's no way to do this with DataBinding. The DotNet BindingManager is not thread-safe and there is no way to make it so. Nothing you can do will ever make it completely safe to have a bound control or a bound data source get modified by a different thread.
The only safe way to do this kind of thing would be to have your background thread retrieve the data and then marshal it over to the UI thread and update the data source on the UI thread. So let's say your background thread retrieves 1000 rows and then maybe uses a timer to sends a collection of 100 rows at a time over to the UI thread in bursts. This way the background thread is completely separated from the UI thread. The only communication between the two is the bursts of data that occur every so often and are marshaled to the UI thread safely.
Hello,
I know this post is relatively old, but I have the same question. One thing I don't understand about your response is that it seems to defeat the purpose of using the background worker in the first place; if you wait until all the data is loaded into the collection before binding the data to the grid, then you could experience a delay (and a frozen UI) while the grid renders the data. What i'm looking for is some kind of design pattern I can apply to all similar projects, but the idea of using a background worker seems to run against the grain with the way that controls work these days with data sources (bind the data source and let the control take as long as it takes to load the data). Any insight would be much appreciated.
Using threads like this can be very dangerous. If the grid is bound to the data source and your code causes the data source to raise a notification which will pass over to the UI Thread without being properly marshalled.
The safest thing to do would be not to bind the grid to the data source until after the worker thread has completed and the data has been properly marhsalled to the UI Thread.