Back to results for “Threading”
.NET MAUI › Concurrency & Threading

What is the UI thread and why must UI updates happen on it?

Beginner

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.

Common follow-ups: How do you check if you're on the UI thread? | What runs off the UI thread?