Skip to content

Which is better MainThread.Being/Invoke... VS Dispatcher.Dispatch... #7518

Answered by mattleibow
michaelstonis asked this question in Q&A
Discussion options

You must be logged in to vote

Good question.

So you are correct, there are different ways to invoke on the main thread:

  • BindableObject.Dispatcher.Dispatch()
  • Dispatcher.GetForCurrentThread().Dispatch()
  • MainThread.BeginInvokeOnMainThread()

All 3 use the same mechanisms under the hood since both use platform APIs to get to the main thread. However, the main difference is the fact that the Dispatcher is coming from a UI object, so always knows which thread to use. The MainThread is static so it is mostly correct. Let me explain.

When you have a UI component (BindableObject, Button, Page, Window), it knows which thread it is assigned to. Some platforms, like Windows and iOS, require that UI objects be created on the UI t…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@HomeroLara
Comment options

@AndreasReitberger
Comment options

@taublast
Comment options

Answer selected by michaelstonis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants