On the main thread?

What does it mean that something has to be ‘executed on the main thread’?
Is running a method in a button press event handler ‘on the main thread’?

Any code outside of a Thread.Run event is on the main thread.

(…right?)

[quote=42519:@Eric Williams]Any code outside of a Thread.Run event is on the main thread.

(…right?)[/quote]
Almost. The main thread is where your code will be running unless your code is called from the Thread.Run event. Any method called from within Thread.Run will run on that thread. Use timers to communicate between the thread and the GUI (the Timer.Action event always runs on the main thread, and it’s always safe to modify a Timer from a thread.)

The main thread is the thread which is responsible for managing events in the user interface. Buttons, ListBoxes, windows, Timers, etc. all run on the main thread. This is why the UI will be unresponsive if the main thread is not allowed to run often enough, and why UI elements shouldn’t be modified from the within the context of a thread.

[quote=42519:@Eric Williams]Any code outside of a Thread.Run event is on the main thread.
(…right?)[/quote]

To clarify : it doesn’t matter where the code IS, it matters where the code has been called FROM.

For example, you could have a method as part of a Thread subclass:

MyThread
  Sub FooBar
       do something
  end sub

And if you called “MyThread.FooBar” from “Pushbutton1.Action”, FooBar would be running on the main thread.

Alternatively, if you call a method from within the Thread.Run event, that method will be running inside the thread. Any methods that it calls would also be running inside a thread. Etc.