Skip to content

UI thread

Category: Units of execution · Status: stub · Lessons: chapter 06, Async (planned)

One line: The one thread a graphical toolkit allows to touch its widgets: long work goes to other threads or tasks, and its results are posted back to that thread.

Also called: main thread, event dispatch thread, GUI thread.

How it connects

flowchart LR
  n_thread["Thread"]
  n_ui_thread["UI thread"]
  n_ui_thread -->|is a| n_thread
  classDef center stroke-width:3px
  class n_ui_thread center
  classDef outside stroke-dasharray: 4 3
  class n_thread outside

In each language

Java Swing's event dispatch thread: SwingUtilities.invokeLater runs code on it
C# Control.Invoke runs a delegate on the thread that owns a Windows Forms control
JavaScript the main thread ↗, where the browser runs user code, handles events and renders; web workers run elsewhere
Swift MainActor, the global actor that performs its tasks on the main thread

Where to read more