This is a migrated thread and some comments may be shown as answers.

RadDataForm + threading = System.InvalidOperationException

1 Answer 102 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Niklas
Top achievements
Rank 1
Niklas asked on 16 Dec 2011, 10:20 PM
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()

1 Answer, 1 is accepted

Sort by
0
Anatoly Chekh
Top achievements
Rank 1
answered on 22 Mar 2012, 10:40 AM
Hello.

What about this issue?

I get error with the same path (c:\TB\117\WPF_Scrum\Release_WPF\Sources\Development\Controls\Data\...) also. So what does it mean?

Thanks, Anatoly.

Tags
DataForm
Asked by
Niklas
Top achievements
Rank 1
Answers by
Anatoly Chekh
Top achievements
Rank 1
Share this question
or