i have problem in updating GUI from another thread
my code gives me exception
i debugged to find the reason of exception

i found that it is here
[ this part of Wedget class

if (display.thread != Thread.currentThread ()) {

if (display.threadId != OS.GetCurrentThreadId ()) {
error (SWT.ERROR_THREAD_INVALID_ACCESS);//hereeeee
}

thanks in advance

Recommended Answers

All 6 Replies

You can only make updates to SWT controls from within the SWT UI thread. You need to use either synExec or asyncExec to accomplish running other code that updates SWT controls because these methods cause the code to be run on the SWT UI thread. See :

http://book.javanb.com/swt-the-standard-widget-toolkit/ch05lev1sec7.html

P.S. you should be saying display.getThread() not display.thread and Thread.currentThread() not OS.getCurrentThread or whatever you are calling. .

thanks a lot sir
is there any other method to do that

my application may do a lot of updates in 1 second so a lot of threads
so bad cpu usage

No, there is no other method to do that. It isn't bad cpu usage. What is your reasoning behind thinking it is bad cpu usage?

my application receives data frames from bus
so if i send a a lot of frames the CPU usage reaches 55%
because of creating new thread for every data received
it is my problem with this method of updating
:-/

The methods I described to you are only for updating UI elements. Not for executing long running tasks. Executing long running tasks on the UI thread (i.e. by calling asynchExec on your code block) is going to freeze up the UI, making it unresponsive to the user.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.