I am trying to set a ViewModel List property from an async method, but this ends with the following error:
{"The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))"}
The error is pretty clear. What is not clear to me is the best approach to overcome this issue and successfully set the property that in turn updates the UI.
The following attempt ends with Object reference not set to an instance of an object Error at the point of Initializing the Dispatcher:
private async Task DoSomething()
{
DispatcherHelper.Initialize();
DispatcherHelper.CheckBeginInvokeOnUI(
() =>
{
ViewModelProperty = SomeResult;
});
}
What is the best approach to solving this problem?