Are multi threaded windows their own “main” thread?

I’m working on a couple of projects and one of them involves multiple windows. I don’t normally have much consideration for having multiple windows open, but this one does need some sort of “display”.

Which got me to thinking…

We talk about the “Main” thread and where the GUI updates are processed and I understand that as modules and windows relate to a single instance.

But what of a window that’s opened in another thread?

I’m not at the computer (on my iPad now while the kids are at swimming lessons, yay!) else I’d run some tests but:

  1. When you load or show a window, via creation of it through via “New”, the originating thread is still the current thread (confirming in my own mind)
  2. If you do create the window in another thread, for all intents and purposes, the application or originating thread is the main thread for itself, and anything run in the new window shouldn’t (can’t) be updating the Main window, but as far as that other (child) window is concerned, it is its own thread and would be considered the main thread for itself… yeah?
  3. Can you (or should you not) have each GUI on its own thread? For example, a drawing application that has a “preview” window (as a seperate window) I would think would be handled on the main thread, even if you are click-holding and dragging the mouse to draw a line, you would handle the update of that preview in a mouse dragging event, but if you opened another window and it was cycling through all the files in a folder and throwing thumbnails in a preview (and say there are thousands of images), you (I) would think you would/could remove that from the main drawing process of your graphic/drawing app. If you do Start a new thread (perhaps from the main app so the apparent parent window could close) then dragging either window around the desktop won’t halt the other/stall
  4. Or is it the case that all GUI related tasks (app and / or system wide) happen on a main thread?

In essence, for the second window in its own thread, does that window consider itself “the main thread”? Or it is the case of #4 where there is only one main thread?

(This isn’t a requirement for my current situation, more of a thought process and proof of concept)

Attempting to use New Window from a thread will raise a ThreadAccessingUIException.

No. Even disregarding the exception, GUI events will always occur on the event loop/main thread.

Excellent, thanks for clarifying that @Andrew Lambert , at least my mind can stop drifting down that rabbit hole :slight_smile: