Question about UI / non-UI listeners [message #780632] |
Wed, 18 January 2012 15:13  |
Eclipse User |
|
|
|
Hi everyone:
I wrote an eclipse plugin, and got many "invalid thread errors". I know that this error is caused by "accessing a GUI object from a non-UI thread", but am *really* confused on the huge volume of "EventListener"s sublclasses in eclipse. I was surprised to find some listeners are called from UI-thread, while others are called from non-UI thread.
For example,
AWTEventListener, IResourceChangeListener and IJobChangeListener all implement the EventListener interface. However, I found the call back method in AWTEventListener is always called by UI-thread, thus the object access code there do not need to be wrapped by sync/asyncExec. But the other two listeners (IResourceChangeListener, and IJobChangeListener) are often called by non-UI thread, if the call back there access some UI object, an invalid thread error becomes apparent.
My question is "which listeners will be called by UI/non-UI thread"? is there any rule for this? If not, do I need to remember (hardcode) those facts?
[I got some answers as follows:
If your non-UI based listener needs to call UI object, this call should happen using asyncExec or syncExec.
For the bigger part of your question, you may get a better answer in the 'Eclipse Platform' forums.
]
I am really interested in knowing what would be the UI/non-UI based listeners in Eclipse's platform.
thanks a lot, any suggestion is highly appreciated.
-Sai
|
|
|
|
Re: Question about UI / non-UI listeners [message #786600 is a reply to message #780632] |
Mon, 30 January 2012 11:10  |
Eclipse User |
|
|
|
Usually it's up to the interface that allows the add*Listener(*) to specify if it's called on the UI thread. The default assumption is listeners can be called back on any worker thread ... except the services and framework provided by org.eclipse.ui. There the assumption should be that it is called on the UI thread *unless* the interface says otherwise.
PW
|
|
|
Powered by
FUDForum. Page generated in 0.03499 seconds