Search code examples
xamarin.formsprismmvvm-light

What is the Prism equivalent of DispatcherHelper?


I am rewriting a code base from MVVMLight to Prism. I have an interface IDispatchOnUIThread that I am implementing in iOS.

What is the equivalent of MVVMLight's DispatchHelper in Prism ?

using MyApp.Model;
using GalaSoft.MvvmLight.Threading;
using System;

namespace MyApp.iOS
{
    public class DispatchOnUIThread : IDispatchOnUIThread
    {
        public void Invoke(Action action)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(action);
        }
    }
}

Solution

  • To my knowledge, there is no such thing in the Prism lib. Maybe cause Xamarin.Forms offers it out of the box: Device.BeginInvokeOnMainThread.

    So you could go:

    namespace MyApp.iOS
    {
        public class DispatchOnUIThread : IDispatchOnUIThread
        {
            public void Invoke(Action action)
            {
                Device.BeginInvokeOnMainThread(action);
            }
        }
    }