Tuesday, January 10, 2017

[HowTo] Call any code on UI thread outside of Activity

using Android.OS;

public class MyThread
{
    public void Run()
    {
        RunOnUiThread(() => DoSomething());
    }

    private void RunOnUiThread(Action action)
    {
        using (var handler = new Handler(Looper.MainLooper))
        {
            handler.Post(action);
        }
    }
}

No comments:

Post a Comment