MainThread (Xamarin.Essentials API of the Week)

Play MainThread (Xamarin.Essentials API of the Week)
Sign in to queue


Xamarin.Essentials provides developers with cross-platform APIs for their mobile applications. On this week's Xamarin.Essential API of the week we take a look at the MainThread API to enable you to check if the code you are about to execute will run on the main user interface thread and a way to invoke code on the main thread if it isn't.

Show Notes:

Useful Links:



The Discussion

  • User profile image

    What is the difference to using Device.BeginInvokeOnMainThread() which is built directly into Xamarin.Forms?

  • User profile image
  • User profile image
    MiKill - there's a comment in the docs that addresses that....

    Xamarin.Forms has a method called Device.BeginInvokeOnMainThread(Action) that does the same thing as MainThread.BeginInvokeOnMainThread(Action). While you can use either method in a Xamarin.Forms app, consider whether or not the calling code has any other need for a dependency on Xamarin.Forms. If not, MainThread.BeginInvokeOnMainThread(Action) is likely a better option.
  • User profile image
    Thanks James, great video, simple and to the point, as usual. How about a 101 on threading in general, perhaps async as well. I have a vague idea about how all these work, but your 101s fill in a lot of gaps.

Add Your 2 Cents