[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Display.getDefault().asyncExec

On Wed, 9 Apr 2008 10:29:27 +0000 (UTC), mr_squirtle23@xxxxxxxxx (Mark
R) wrote:

>Hello,
>
>I am debugging an SWT program written by someone and I keep on 
>encountering the code
>
>Display.getDefault().asyncExec(new Runnable()
>{
>public void run() {
>//many code
>}
>}
>
>I really dont get what this code does. I tried googling for this phrase 
>but cant found a nice resource to learn about this.  Does someone has link 
>discussing about this?
>Please bear with me as I really am starting to know about SWT.

Your are not allowed to access SWT components from another thread than
the one they were created in. If you do you'll get an exception.
Usually you have exactly one thread where SWT components are handled,
called the (G)UI thread. The code above executes the Runnable in the
thread associated with the default (and probably only) Display.

asyncExec() dispatches the Runnable and continues in your current
thread. The Runnable is executed (probably later) in the UI thread
when all previous scheduled events have been processed. If you use a
syncExec() call, your current thread will wait until the Runnable has
been executed.

Achim
-- 
Achim Lörke

Eclipse-Stammtisch in the Braunschweig, Germany area:
http://www.bredex.de/de/career/eclipse.html