[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: Updating a widget from a background running thread

Eclipse's help, when you install eclipse, will tell you more how to handle threading issues in Eclipse. From the Eclipse IDE, do "Help->Help Contents". Type in "Thread" as your search keyword. Then choose "Threading Issues" from the results of the search.

Xavier wrote:

Thanks Daniel for this trick and tip... I thought at something like a
synchronized(myThread){
...
}
but i didn't work of course :-(

I'll integrate the code tomorrow...
regards
Xavier

Daniel Spiewak a écrit :

    ...
*    final* Display display = *new* Display();
    Thread thread = *new* Thread(*new* Runnable() {
        *public void* run() {
           ...
           // thread code goes here
           display.syncExec(*new* Runnable() {
              *public void* run() {
                 // enter your updating code here
              }
           });
           ...
        }
    }).start();
    ...

Technically, the code within the syncExec(Runnable) block isn't actually being run inside your other thread, It's being run inside the event dispatch loop (i.e while(!shell.isDisposed()) if (!display.readAndDispatch()) ...) However, this should clear up your problem. It would be best if you can keep just the ui updating code within the syncExec(Runnable) block and do as much as possible outside the block in your Thread. Otherwise your ui will start to bog down.

Daniel

Xavier wrote:

Hello,
I would like to update for instance a text field in a view from a Thread running in background. Unfortunately, this throws an error because we try to update the field from another thread wich is not a "graphical" thread.
Is there a simple means to do that properly?
regards
Xavier