Display类的syncExec()和asyncExec()之间的区别 [英] Difference between syncExec() and asyncExec() of Display class

查看:485
本文介绍了Display类的syncExec()和asyncExec()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse后台处理的插件项目中。

syncExec() asyncExec()方法的 Display 类?它们在哪些情况下适用?任何示例都可能有帮助。

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 class? In which situations are they applicable? Any example could be helpful.

推荐答案

来自问:为什么会出现错误 org.eclipse.swt.SWTException:无效的线程访问?


为允许后台线程对属于UI线程的对象执行操作,请使用Display的syncExec(Runnable runnable)和asyncExec(Runnable runnable)方法。这些是SWT中唯一可以从任何线程调用的方法。它们允许UI线程同步地执行可运行对象,从而使后台线程等待该可运行对象完成,或者异步地允许后台线程继续执行而无需等待结果。使用syncExec()执行的可运行对象与对UI操作的等效直接调用最接近,因为Java方法调用始终在继续之前等待结果,就像syncExec()一样。

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().

这篇关于Display类的syncExec()和asyncExec()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆