PropertyGrid: Cross-thread operation not valid

Grids for WPF Forum

Posted 9 years ago by Doug Witt - Woodward
Version: 14.2.0611

I keep getting an error when I am setting the SelectedObjects property on the PropertyGrid.  My application is a mix of WPF and WinForms.  The objects that I am assigning to the SelectedObjects property are WinForms objects.  Here is the stack trace that I get:


A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Unhandled Exception on thread: System.InvalidOperationException Cross-thread operation not valid: Control 'TrendChart' accessed from a thread other than the thread it was created on.
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Design.DocumentDesigner.OnComponentChanged(Object sender, ComponentChangedEventArgs e)
at System.ComponentModel.Design.ComponentChangedEventHandler.Invoke(Object sender, ComponentChangedEventArgs e)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IComponentChangeService.OnComponentChanged(Object component, MemberDescriptor member, Object oldValue, Object newValue)
at System.ComponentModel.ReflectEventDescriptor.RemoveEventHandler(Object component, Delegate value)
at System.ComponentModel.ReflectPropertyDescriptor.RemoveValueChanged(Object component, EventHandler handler)
at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyDescriptorDataAccessor.#Cdb.#bn()
at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyDescriptorDataAccessor.Dispose(Boolean disposing)
at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.DataAccessorBase.Finalize()


I have set the IsAsynchronous to false for the PropertyGrid:

<pg:PropertyGrid Grid.Row="1" Margin="15,40,15,0" SelectedObject="{Binding SelectedObject}" SelectedObjects ="{Binding SelectedObjects}" IsAsynchronous="False" />

Any ideas on how I can get around this?

Comments (3)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Doug,

Hmmm, that is a rather tricky situation since it seems like you are trying to use the PropertyGrid to reflect on and update an object that originates from a different thread in your application.  As you see, whenever you try to access an object from another thread in .NET, you get that sort of exception.

The only thing I can really recommend is to have some sort of proxy object that would "wrap" your TrendChart object with similar public properties you want to see in the PropertyGrid.  Then use the various techniques described on the web within those wrapper properties to perform cross thread communication using Invoke() calls, etc.  That would hopefully prevent the exception from occurring.

Actipro Software Support

Posted 9 years ago by Doug Witt - Woodward


Looking at the call stack, this code is running on the Finalizer thread, and not the UI thread.  My understanding of the Finalize is that you should only be disposing of unmanged resources, not accesing managed objects, as this can cause issues with threading.  Your code is obfuscated, so I cannot see it, but the call stack shows that your are calling the PropertyDescriptorDataAccessor.Dispose which accesses the ReflectPropertyDescriptor managed object.   I'm wondering if this is a mistake in your PropertyDescriptorDataAccessor.Dispose(Boolean disposing) implementation?

Do you expect the PropertyDescriptorDataAccessor to be disposed by me and not the finalizer?  Should I be using your API differently to ensure this is disposed, and not have the finalizer call the dispose?


Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Doug,

Based on what you found, we've made some code updates that we'd like you to try out before we include them in the next version.  Can you email our support address, reference this thread, and we'll send you a preview build to try?

Actipro Software Support

The latest build of this product (v24.1.2) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.