Multi-threaded GUI

Jacob Carlborg doob at me.com
Thu Jul 26 04:55:43 PDT 2012


On 2012-07-26 11:45, Gor Gyolchanyan wrote:

> So the good way to do this will be to have a single thread, which pumps
> messages and distributes the appropriate message handlers to worker
> threads, right?

It should be possible to have other threads interacting with the GUI as 
long as they do that by sending messages to the thread responsible to 
for GUI. Here's an example of an SWT snippet that does GUI manipulation 
from a different thread:

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet130.java

On line 42 a new thread is created. On line 48 the GUI is changed, by 
adding a string to some text widget. But this happens using the 
"display.syncExec" method. This force the code to be executed on the GUI 
thread instead of the current thread.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list