This two days to write a WPF client, bind a ObservableCollection data source for the DataGrid, but it is so simple a thing, after the completion of the execution occurs bug,bug page as follows:
Find problems and solutions with Google. The problem is that in a multithreaded environment, the update operation on the data source collection conflicts with the display of the UI thread. How to solve? Look underneath.
void Updateitems () {//retrieveditems is the data of the received from the service foreach (object item in Retrievedite ms) Dispatcher.begininvoke (Dispatcherpriority.background, New Parameterizedthreadstart (AddItem), item); } void AddItem (Object item) { Observablecollection.add (item);}
Just use this asynchronous update, OK, the bug is done.
SOURCE Link here: Http://stackoverflow.com/questions/2505492/wpf-update-binding-in-a-background-thread
Finally sigh, the Chinese resources is very little Ah, Google problems or to use English, the above question with the following sentence to search
an ItemsControl are inconsistent with its items source, it will be able to search a bunch of solutions on the StackOverflow.
Multithreaded exception: A ItemsControl is inconsistent with its entry source