|Question about UI / non-UI listeners [message #780632]
||Wed, 18 January 2012 20:13
| Sai Missing name
Registered: March 2011
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.
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.
Powered by FUDForum
. Page generated in 0.05246 seconds