Eclipse RCP多线程 [英] Eclipse RCP multithreading

查看:93
本文介绍了Eclipse RCP多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个eclipse rcp应用程序.当执行此命令时,我有一条命令.我需要启动一个线程.执行此线程后,必须更新GUI.但是我想这个线程或其他非SWT线程无法更新GUI.但这似乎是合理的.当我尝试这样做时,我在线程"Thread-5" org.eclipse.swt.SWTException中得到了 Exception:无效的线程访问.我该如何实现这个目标?

I have an eclipse rcp application. And I have a command when this command is executing. I need to start a thread. After execution of this thread GUI must be updated. But I suppose that this thread or other non-SWT thread cannot update GUI. But it seems reasonable. When I was trying to do that I got Exception in thread "Thread-5" org.eclipse.swt.SWTException: Invalid thread access. How I can make this goal?

推荐答案

使用SWT,您需要在主线程上进行任何可更新GUI的操作,或者在Eclipse中,它被称为UI线程(是同一线程).之所以出现此错误,是因为您试图访问另一个线程上的SWT对象.考虑使用 Display.syncExec() Display.asyncExec()将SWT相关的处理移至主线程.您要小心使用 syncExec()不会导致死锁.

Using SWT you need to have anything that updates the GUI be done on the main thread, or in Eclipse, it's called the UI thread (it's the same thread). You are getting this error because you are trying to access an SWT object on another thread. Consider using Display.syncExec() or Display.asyncExec() to move the SWT related processing to the main thread. You want to be careful with syncExec() that you don't cause a deadlock.

这篇关于Eclipse RCP多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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