What is the UI thread and why must UI updates happen on it?
Short answer
Each platform has a single main/UI thread that owns the visual tree; touching UI from another thread causes exceptions or corruption.
Advertisement
AModel answer
Each platform has a single main/UI thread that owns the visual tree; touching UI from another thread causes exceptions or corruption. Async I/O runs off the UI thread, but results that mutate UI must be marshaled back with MainThread.BeginInvokeOnMainThread (or InvokeOnMainThreadAsync).
MainThread.BeginInvokeOnMainThread(() => statusLabel.Text = "Done");Real-world example
A background download updates a progress label only after marshaling back to the UI thread, avoiding a cross-thread crash.
Likely follow-ups
- How do you check if you're on the UI thread? | What runs off the UI thread?
Related topics