1

I'm using MVVM-Light with Windows Template Studio. My app works fine but when i open a view/viewmodel in a separate windows using WTS's WindowManagerService it gives me this error:

"System.Exception: 'The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))'"

I've fixed this in the past using my own InotifyBase and wrapping it in a coredispatcher but I can't do that with MVVM-Lights INotify implementation... I've tried variations of what's below but nothing works. I would think a ton of people are doing this but i can't find anything and anything I have found was vague or incomplete.

private bool _masterCollapse;
public bool MasterCollapse
{
    get { return _masterCollapse; }
    set
    {
        DispatcherHelper.UIDispatcher.RunAsync(CoreDispatcherPriority.Normal,() => Set(ref _masterCollapse, value));
    }
}
  • well there are some different way of thinking here; i would say its better to make sure you are on the UI thread before you are changing properties; especially when settings multiple properties to avoid context switching – Dave Smits Mar 31 '18 at 15:25
  • How would I do that? When i open the UI in a different window I can't put it and the VM on the same thread. – beatnikthedan Mar 31 '18 at 15:52
  • need some info of your vm. but the method that sets the property ispatcherHelper.UIDispatcher.RunAsync(CoreDispatcherPriority.Normal,() => { this.MasterCollapse = true }) – Dave Smits Mar 31 '18 at 16:08
  • What? the "Set(ref _masterCollapse, value)" method is part of MVVM Light. I have no access to it otherwise i'd fix it and put it on my thread. that is the whole point of my question – beatnikthedan Apr 01 '18 at 01:29
  • i mean your method; that Sets MasterCollapse property. – Dave Smits Apr 01 '18 at 12:04
  • This is a property that is bound to a XAML control. But that isn't relevant. I have several hundred properties that are set using MVVM Lights implementation of IPNC this is just one of those. NONE of them work when I open a second window to my app because that second window is running on a different thread and freaks out whenever I try to update a property. Forget about what I have, I need a way to accomplish what I detailed I need to do – beatnikthedan May 07 '18 at 15:44

0 Answers0