UI Thread issue with view model in MVVMCross

Did you try IMvxMainThreadDispatcher?

var dispatcher = Mvx.Resolve<IMvxMainThreadDispatcher>();
dispatcher.RequestMainThreadAction(()=> { .... });

See more on the implementation:

https://github.com/MvvmCross/MvvmCross/search?q=IMvxMainThreadDispatcher&type=Code

Usually I don't think you need this though.

Since you start the async processing from main thread, the async operations should return back to main thread.

Can you give an example of the async code you are doing?


Method RequestMainThreadAction is now obsolete. Today you have to do

var dispatcher = Mvx.Resolve<IMvxMainThreadAsyncDispatcher>();
await dispatcher.ExecuteOnMainThreadAsync(()=> { .... });

Update on 24th August 2020: As @claudio-redi has mentioned, ExecuteOnMainThreadAsync needs to be used. But Mvx.Resolve is now obsolete. So the latest snippet would be:

var mainThreadAsyncDispatcher = Mvx.IoCProvider.Resolve<IMvxMainThreadAsyncDispatcher>();
await mainThreadAsyncDispatcher.ExecuteOnMainThreadAsync( async ()=> { await SomeAsyncTask() });

Tags:

Mvvm

Mvvmcross