MainThread (Xamarin.Essentials API of the Week)

Play MainThread (Xamarin.Essentials API of the Week)

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.
  • User profile image
    I was curious about updating properties when the UI is bound to properties in MVVM.
    I did a check (MainThread.IsMainThread) when setting properties on a page, and noticed when properties are being updated from events, the property updates are not being updated on the main thread. What is puzzling however, is that the app doesn't throw an exception/crash.

    I am starting to wrap these cases with MainThread.BeginInvokeOnMainThread(() =>{}) but sure would like to understand that better!

Add Your 2 Cents