Here is my scenarion:
I have a GridControl bound to a BindingList. At first what I was doing was creating a worker thread and access the BindingList directly, but this was throwing a “Cross-thread operation detected”, so I followed the guide here:
http://www.devexpress.com/Support/Center/p/AK2981.aspx
By cloning the original BindingList into the worker thread and changing that one, I got the desired effect. However, I recently implemeneted the INotifyPropertyChanged into the object that is held into the BindingList, and I started getting the error again.
My guess is that the GridView is still listening to the INotifyPropertyChanged from the object.
How can I fix this?
My class:
public class Proxy : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
If you are manipulating the UI from outside of the UI thread (such as from a worker thread), then you need to rejoin the UI thread. You can do this by calling
Invokeon the UI control. You can test if this is required by usingInvokeRequired.The pattern typically used is this:
In your case the UI is being manipulated as a result of
INotifyPropertyChanged, so you need to make sure that either you always modify your entity on the UI thread (using the above technique), or use a generic asynchronous INotifyPropertyChanged helper. This is a wrapper around the item being bound. It uses the above technique to ensure theChangePropertyevent fires on the UI thread.Here’s a very crude example of a proxy for an
Entityclass. This ensures that the property change event rejoins the UI thread, and keeps the entity itself unmodified. Obviously you’ll probably want to implement this more generically using DynamicObject for instance.