I have bound the ItemsSource of my RadDataForm to a custom collection derived from ObservableCollection<T>.
In the collection class I have a method called "Populate". What it does, is it basically just makes an http request in a new thread and then adds items from the http request to the collection.
When calling ObservableCollection<T>.Add() from the new thread, I get a System.InvalidOperationException with the message "The calling thread cannot access this object because a different thread owns it".
The stacktrace lead me to RadDataForm (pasted below). Should RadDataForm be thread safe?
at System.Windows.DependencyObject.SetValue(DependencyPropertyKey key, Object value)
at Telerik.Windows.Controls.RadDataForm.set_CanAddItems(Boolean value) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Data\DataForm\RadDataForm.cs:line 1367
at Telerik.Windows.Controls.RadDataForm.SetCanAddItems() in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Data\DataForm\RadDataForm.cs:line 1510
at Telerik.Windows.Controls.RadDataForm.SetAllCanProperties() in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Data\DataForm\RadDataForm.cs:line 1525
at Telerik.Windows.Controls.RadDataForm.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Data\DataForm\RadDataForm.cs:line 768
at Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.cs:line 636
at Telerik.Windows.Data.DataItemCollection.OnCollectionViewCollectionChanged(NotifyCollectionChangedEventArgs e) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.cs:line 615
at Telerik.Windows.Data.DataItemCollection.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs e) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.cs:line 1050
at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\WeakEvents\WeakEvent.cs:line 33
at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 900
at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChangedWithAdjustedArgs(NotifyCollectionChangedEventArgs originalArguments, Int32 adjustedOldIndex, Int32 adjustedNewIndex) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1499
at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1366
at Telerik.Windows.Data.QueryableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1263
at Telerik.Windows.Data.QueryableCollectionView.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1739
at Telerik.Windows.Data.QueryableCollectionView.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1718
at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\WeakEvents\WeakEvent.cs:line 33
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at My.Project.ModelCollection`1.<Populate>b__3(IQueryResult result) in D:\myproject\ModelCollection.cs:line 67
....something clipped....
at System.Threading.Tasks.Task.Execute()
In the collection class I have a method called "Populate". What it does, is it basically just makes an http request in a new thread and then adds items from the http request to the collection.
When calling ObservableCollection<T>.Add() from the new thread, I get a System.InvalidOperationException with the message "The calling thread cannot access this object because a different thread owns it".
The stacktrace lead me to RadDataForm (pasted below). Should RadDataForm be thread safe?
at System.Windows.DependencyObject.SetValue(DependencyPropertyKey key, Object value)
at Telerik.Windows.Controls.RadDataForm.set_CanAddItems(Boolean value) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Data\DataForm\RadDataForm.cs:line 1367
at Telerik.Windows.Controls.RadDataForm.SetCanAddItems() in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Data\DataForm\RadDataForm.cs:line 1510
at Telerik.Windows.Controls.RadDataForm.SetAllCanProperties() in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Data\DataForm\RadDataForm.cs:line 1525
at Telerik.Windows.Controls.RadDataForm.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Data\DataForm\RadDataForm.cs:line 768
at Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.cs:line 636
at Telerik.Windows.Data.DataItemCollection.OnCollectionViewCollectionChanged(NotifyCollectionChangedEventArgs e) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.cs:line 615
at Telerik.Windows.Data.DataItemCollection.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs e) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.cs:line 1050
at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\WeakEvents\WeakEvent.cs:line 33
at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 900
at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChangedWithAdjustedArgs(NotifyCollectionChangedEventArgs originalArguments, Int32 adjustedOldIndex, Int32 adjustedNewIndex) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1499
at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1366
at Telerik.Windows.Data.QueryableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1263
at Telerik.Windows.Data.QueryableCollectionView.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1739
at Telerik.Windows.Data.QueryableCollectionView.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1718
at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args) in c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\WeakEvents\WeakEvent.cs:line 33
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at My.Project.ModelCollection`1.<Populate>b__3(IQueryResult result) in D:\myproject\ModelCollection.cs:line 67
....something clipped....
at System.Threading.Tasks.Task.Execute()