runInGuiThread

Runs the given code in the GUI thread when its event loop is available, blocking until it completes. This allows you to create and manipulate windows from another thread without invoking undefined behavior.

If this is the gui thread, it runs the code immediately.

If no gui thread exists yet, the current thread is assumed to be it. Attempting to create windows or run the event loop in any other thread will cause an assertion failure.

More...
@trusted
bool
runInGuiThread
(
scope void delegate
()
dg
)

Return Value

Type: bool

true if the function was called, false if it was not. The function may not be called because the gui thread had already terminated by the time you called this.

Detailed Description

Did you know you can use UFCS on delegate literals?

() { // code here }.runInGuiThread;

Meta

History

Added April 10, 2020 (v7.2.0)

Return value added and implementation tweaked to avoid locking at program termination on February 24, 2021 (v9.2.1).