Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » View refresh problem
View refresh problem [message #448941] Sat, 15 January 2005 14:50 Go to next message
Eclipse UserFriend
Originally posted by: dicesCAVA.ctonet.it

If i refresh my view from new Thread throw this exception:

org.eclipse.swt.SWTException: Invalid thread access

code is this:
public void myMethod(){
new Thread(){
textViewer.getDocument().set(veryHeavyMethod()); //veryHeavyMethod
return a string
textViewer.refresh();
}.start();
}

why this exception?
--
(Sorry for my spaghetti english)
Re: View refresh problem [message #448946 is a reply to message #448941] Sat, 15 January 2005 20:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nickthat.yahoo.com

The problem is that you are only allowed to make certain GUI calls on the
main thread. If you have an operation that takes a long time, you can have
it run on the main thread as a sort of thread i.e. when there are no
messages being processed. This is done by using the method call.

Display.getCurrent().asyncExec(myThread)


SaThot wrote:

> If i refresh my view from new Thread throw this exception:

> org.eclipse.swt.SWTException: Invalid thread access

> code is this:
> public void myMethod(){
> new Thread(){
> textViewer.getDocument().set(veryHeavyMethod()); //veryHeavyMethod
> return a string
> textViewer.refresh();
> }.start();
> }

> why this exception?
Re: View refresh problem [message #448950 is a reply to message #448946] Sun, 16 January 2005 12:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dicesCAVA.ctonet.it

On Sat, 15 Jan 2005 20:43:39 +0000 (UTC), Nick Thatcher
<nickthat@yahoo.com> wrote:

> The problem is that you are only allowed to make certain GUI calls on
> the main thread. If you have an operation that takes a long time, you
> can have it run on the main thread as a sort of thread i.e. when there
> are no messages being processed. This is done by using the method call.
>
> Display.getCurrent().asyncExec(myThread)

Ok, it working but gui is freezed too

--
(Sorry for my spaghetti english)
Re: View refresh problem [message #448964 is a reply to message #448950] Mon, 17 January 2005 07:57 Go to previous messageGo to next message
Stefan Pietsch is currently offline Stefan PietschFriend
Messages: 68
Registered: July 2009
Member
Hi,

you have to call veryHeavyMethod() in a separat thread and store the result
in a string. Then this thread calls another thread with
Display.getCurrent().asyncExec(). The second thread calls
textViewer.getDocument().set() with the stored string.

public void myMethod(){
new Thread(){
final String s = veryHeavyMethod();
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
textViewer.getDocument().set(s);
textViewer.refresh();
}
});
}.start();
}


Bye Stefan

"SaThot" <dicesCAVA@ctonet.it> schrieb im Newsbeitrag
news:opsko4udxa5horlisaDjehwty@djehwty.mes...
> On Sat, 15 Jan 2005 20:43:39 +0000 (UTC), Nick Thatcher
> <nickthat@yahoo.com> wrote:
>
> > The problem is that you are only allowed to make certain GUI calls on
> > the main thread. If hyou have an operation that takes a long time, you
> > can have it run on the main thread as a sort of thread i.e. when there
> > are no messages being processed. This is done by using the method call.
> >
> > Display.getCurrent().asyncExec(myThread)
>
> Ok, it working but gui is freezed too
>
> --
> (Sorry for my spaghetti english)
Re: View refresh problem [message #448989 is a reply to message #448964] Mon, 17 January 2005 12:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dicesCAVA.ctonet.it

On Mon, 17 Jan 2005 08:57:07 +0100, Stefan Pietsch <pietsch@multichart.de>
wrote:

> Hi,
>
> you have to call veryHeavyMethod() in a separat thread and store the
> result
> in a string. Then this thread calls another thread with
> Display.getCurrent().asyncExec(). The second thread calls
> textViewer.getDocument().set() with the stored string.
>
> public void myMethod(){
> new Thread(){
> final String s = veryHeavyMethod();
> Display.getCurrent().asyncExec(new Runnable() {
> public void run() {
> textViewer.getDocument().set(s);
> textViewer.refresh();
> }
> });
> }.start();
> }

if do that Display.getCurrent return null.
Re: View refresh problem [message #449088 is a reply to message #448989] Tue, 18 January 2005 08:50 Go to previous message
Stefan Pietsch is currently offline Stefan PietschFriend
Messages: 68
Registered: July 2009
Member
Hi,

I'm sorry, because I have not checked out the code.

I use a static var in my application to store the main display:

public class MyApplication {
public static Display display.
public MyApplication() {
display = new Display();
...
}
}

So I can use this static var in my threads like:

MyApplication.display.asyncExec().

Bye Stefan

"SaThot" <dicesCAVA@ctonet.it> schrieb im Newsbeitrag
news:opskqxopol5horlisaDjehwty@djehwty.mes...
> On Mon, 17 Jan 2005 08:57:07 +0100, Stefan Pietsch <pietsch@multichart.de>
> wrote:
>
> > Hi,
> >
> > you have to call veryHeavyMethod() in a separat thread and store the
> > result
> > in a string. Then this thread calls another thread with
> > Display.getCurrent().asyncExec(). The second thread calls
> > textViewer.getDocument().set() with the stored string.
> >
> > public void myMethod(){
> > new Thread(){
> > final String s = veryHeavyMethod();
> > Display.getCurrent().asyncExec(new Runnable() {
> > public void run() {
> > textViewer.getDocument().set(s);
> > textViewer.refresh();
> > }
> > });
> > }.start();
> > }
>
> if do that Display.getCurrent return null.
Previous Topic:path to images?
Next Topic:How to handle the right mouse button
Goto Forum:
  


Current Time: Tue Apr 16 20:17:21 GMT 2024

Powered by FUDForum. Page generated in 0.86036 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top