Cross-Thread Exception on PropertyChanged

6 posts, 0 answers
  1. Ruben
    Ruben avatar
    1 posts
    Member since:
    Oct 2012

    Posted 11 Oct 2012 Link to this post

    Hi,

    I have bound to a TreeListView a collection of instances that raise the PropertyChanged from a thread that is not the main UI thread (the event is raised from a FileSystemWatcher event). When PropertyChanged is risen I meet the following exception:

    InvalidOperationException was unhandled: The calling thread cannot access this object because a different thread owns it.

       en System.Windows.Threading.Dispatcher.VerifyAccess()
       en System.Windows.DependencyObject.GetValue(DependencyProperty dp)
       en Telerik.Windows.Controls.RadRowItem.get_Item() en c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\RadRowItem.cs:línea 30
       en Telerik.Windows.Controls.GridView.GridViewRow.BeginProcessDataItemPropertyChanged(Object dataItem, String propertyName) en c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Rows\GridViewRow.cs:línea 2201
       en Telerik.Windows.Controls.GridView.GridViewRow.Telerik.Windows.Data.IWeakEventListener<System.ComponentModel.PropertyChangedEventArgs>.ReceiveWeakEvent(Object sender, PropertyChangedEventArgs args) en c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Rows\GridViewRow.cs:línea 2196
       en Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args) en c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\WeakEvents\WeakEvent.cs:línea 33
       en System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
       en RadControlsWpfApp1.NodoFile.OnPropertyChanged(String propiedad) en g:\Users\Ruben\Mis documentos\Visual Studio 2012\Projects\RadControlsWpfApp1\RadControlsWpfApp1\NodoFile.cs:línea 66
       en RadControlsWpfApp1.NodoFile.set_Nombre(String value) en g:\Users\Ruben\Mis documentos\Visual Studio 2012\Projects\RadControlsWpfApp1\RadControlsWpfApp1\NodoFile.cs:línea 42
       en RadControlsWpfApp1.NodoFile._watch_Renamed(Object sender, RenamedEventArgs e) en g:\Users\Ruben\Mis documentos\Visual Studio 2012\Projects\RadControlsWpfApp1\RadControlsWpfApp1\NodoFile.cs:línea 48
       en System.IO.FileSystemWatcher.OnRenamed(RenamedEventArgs e)
       en System.IO.FileSystemWatcher.NotifyRenameEventArgs(WatcherChangeTypes action, String name, String oldName)
       en System.IO.FileSystemWatcher.CompletionStatusChanged(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* overlappedPointer)
       en System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

    It really surprised me because I've previously bound other telerik WPF controls in an analogue situation and they worked flawlessly. Having a peek on GridViewRow.BeginProcessDataItemProperty I've noticed that it makes a call through the Dispatcher (which should avoid the exception) but the call to retrieve the dataItem for the row is outside the Dispatcher.BeginInvoke and that's (I pressume) the cause of the exception.

    I don't know if this is intended behaviour or just a little bug but any feedback would be greatly appreciated.

    Thanks in advance.


  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 11 Oct 2012 Link to this post

    Hello,

     We've fixed this problem and the fix will be part of our upcoming official Q3 2012 release next week. 

    Greetings,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. John
    John avatar
    2 posts
    Member since:
    May 2013

    Posted 22 Aug 2013 Link to this post

    Hello,

    I've encountered a similar issue within a different control and I was wondering if it was a known issue and has been fixed in a more recent release of RadControls (we're using 2013 Q1).  Here's a stack trace:

    System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
       at System.Windows.DependencyObject.GetValue(DependencyProperty dp)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.GetRowForItem(Object item, Boolean forceGroupExpand)
       at Telerik.Windows.Controls.GridView.GridViewDataControl.Telerik.Windows.Data.IWeakEventListener<System.ComponentModel.PropertyChangedEventArgs>.ReceiveWeakEvent(Object sender, PropertyChangedEventArgs args)
       at Dominos.ObjectModel.ObservableObject.SetValue[T](String propertyName, T newValue, T& oldValue)
       at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap)
       --- End of inner exception stack trace ---
       at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap)
       at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.Map(ResolutionContext context, IMappingEngineRunner mapper)
       at AutoMapper.Mappers.TypeMapMapper.Map(ResolutionContext context, IMappingEngineRunner mapper)
       at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
       at AutoMapper.MappingEngine.DynamicMap[TSource,TDestination](TSource source, TDestination destination)

    Thank you.
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 26 Aug 2013 Link to this post

    Hi,

    Which version are you using.

    We have rewritten our entire cross-thread functionality from scratch and now we try to dispatch everything on the UI thread to avoid exception like this one. Can you please try with our Latest Internal Build version from previous Monday and see whether the exception will be gone? In case you still get the exception, can you please tell us how to reproduce it? Thanks in advance.

    Regards,
    Rossen Hristov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. John
    John avatar
    2 posts
    Member since:
    May 2013

    Posted 26 Aug 2013 Link to this post

    We are currently using version 2013.1.403.40.  If your changes are in a more recent version, then I'll try it out.

    Thanks for your response.
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 26 Aug 2013 Link to this post

    Hello,

    It was fixed on April the 10th just after your version.

    Regards,
    Rossen Hristov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready