I have a DevExpress GridControl bound to a BindingList.
I tried to modify the BindingList from a thread and this threw an exception, I googled it and found the following explanation:
This issue is not connected with the XtraGrid directly. Unfortunately, you can't change the grid's data source in a background thread since it will cause a lot of problems with synchronization. The XtraGrid may perform some operations with the underlying data source at the same time as your background thread changes it. In this case the grid may receive a Change notification later and will try to update rows from the data source which will cause the mentioned problem. This problem may occur in a lot of cases. For example, when a user edits data, groups it or the XtraGrid tries to recalculate the summaries. The only solution to this problem is to change the Grid's DataSource reference within a background thread (NOTE: You will need to implement it using the Invoke method). Said differently, within a background thread you should work with a local copy of the DataSource and pass its clone to the Grid's DataSource when necessary. In the attached example you will find a sample project which demonstrates this approach.
I tried what it said, resulting in this:
proxyWorker = new Thread(() =>
{
//Clone the datasource into the thread
BindingList<Proxy> newList = new BindingList<Proxy>(proxies);
//Set the proxy source to the cloned datasource in the thread
gcProxies.BeginInvoke(new MethodInvoker(delegate { gcProxies.DataSource = newList; }));
//Logic here
});
proxyWorker.Name = "proxyTester";
proxyWorker.Start();
It works, but what I don't understand is what happens to the datasource after the thread ends? Isn't newList
destroyed?
What I was thinking is that at the end I would reclone newList and set it back into proxies
(the original datasource)