Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » SWTException: Invalid thread access
SWTException: Invalid thread access [message #146175] Sat, 18 October 2003 08:10 Go to next message
Eclipse UserFriend
Originally posted by: tcn.spamgourmet.com

Hi!

I have some thread problem...

class Plugin
{
public void createPartControl(Composite parent)
{
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
...

// this is not the right place, is it?
new SomeThread(this).start();
}

public add(Object blah)
{
view.add(blah);
}
}

class SomeThread extends Thread
{
Plugin ref;

public SomeThread(Plugin ref)
{
this.ref = ref;
}

private run()
{
ref.add(blah);
}
}

This does throw an Invalid thread access exception.

Why? What does it mean? What am I doing now? :-)

Thanks!
Timo
Re: SWTException: Invalid thread access [message #146184 is a reply to message #146175] Sat, 18 October 2003 09:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tcn.spamgourmet.com

Timo Nentwig wrote:

> public add(Object blah)
> {
> view.add(blah);
> }

Pardon, viewer.add(blah), of course :-)
Re: SWTException: Invalid thread access [message #146235 is a reply to message #146175] Sat, 18 October 2003 10:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tcn.spamgourmet.com

Timo Nentwig wrote:
> class Plugin

public class Plugin extends ViewPart

:-)
Re: SWTException: Invalid thread access [message #146252 is a reply to message #146175] Sat, 18 October 2003 11:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: akiezun.cuthis.mit.edu.andthis

it's an FAQ:
(link might get broken)
http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform -swt-home/faq.html?rev=HEAD&content-type=text/html#uithr ead

a.
Re: SWTException: Invalid thread access [message #146261 is a reply to message #146175] Sat, 18 October 2003 12:19 Go to previous message
Eclipse UserFriend
Originally posted by: pdenno.shaw.ca

Timo Nentwig wrote:
> Hi!
>
> I have some thread problem...
>
> class Plugin
> {
> public void createPartControl(Composite parent)
> {
> viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
> ...
>
> // this is not the right place, is it?
> new SomeThread(this).start();
> }
>
> public add(Object blah)
> {
> view.add(blah);
> }
> }
>
> class SomeThread extends Thread
> {
> Plugin ref;
>
> public SomeThread(Plugin ref)
> {
> this.ref = ref;
> }
>
> private run()
> {
> ref.add(blah);
> }
> }
>
> This does throw an Invalid thread access exception.
>
> Why? What does it mean? What am I doing now? :-)
>
> Thanks!
> Timo
You cannot reference a widget from a thread which did not create
it. In the example above you have created the table viewer in the main
thread but are adding elements to it in a different thread.

You can use Display.syncExec or Display.asyncExec to acheive what you want.
Previous Topic:"Completing installation" each time eclipse is started up
Next Topic:JDT Hacking Questions (CVS, Branches, Config)
Goto Forum:
  


Current Time: Fri May 02 14:37:06 EDT 2025

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

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

Back to the top