Function Window.executeInUiThread
Schedule a delegate to run on the UI thread from a background thread.
void executeInUiThread(
void delegate() runnable
);
The application's main thread runs the UI event loop, so any code invoked directly from widget callbacks or signals is already on the UI thread and needs no special handling. This method is for the opposite direction: a worker thread that needs to update widgets or shared state once its work is done.
Internally, runnable is wrapped in a RunnableEvent and
appended to the window's thread-safe event queue. The UI event loop
drains that queue each iteration via handlePostedEvents and
calls the delegate on the UI thread. This method returns immediately;
the delegate runs on a future event loop tick.
Widgets and any data structures owned by the UI must only be accessed on the UI thread. Capture the values the thread needs before spawning it, then use this method to write results back.
See Also
examples/bgthread for a complete working example.