Difference between syncExec() and asyncExec() of Display class

前端 未结 3 1867
一生所求
一生所求 2020-12-16 15:26

I\'m working on a plugin project in which I\'m using Eclipse background processing.
What\'s the difference between the syncExec() and asyncExec() methods of the Display

3条回答
  •  鱼传尺愫
    2020-12-16 16:00

    from Q: Why do I get the error "org.eclipse.swt.SWTException: Invalid thread access"?

    To allow background threads to perform operations on objects belonging to the UI-thread, the methods syncExec(Runnable runnable) and asyncExec(Runnable runnable) of Display are used. These are the only methods in SWT that can be called from any thread. They allow a runnable to be executed by the UI-thread, either synchronously, causing the background thread to wait for the runnable to finish, or asynchronously allowing the background thread to continue execution without waiting for the result. A runnable that is executed using syncExec() most closely matches the equivalent direct call to the UI operation because a Java method call always waits for the result before proceeding, just like syncExec().

提交回复
热议问题