1.

Why Do I Get The Error “org.eclipse.swt.swtexception: Invalid Thread Access”?

Answer»

SWT implements a single-threaded UI model often called apartment threading. In this model, only the UI-thread can INVOKE UI operations. SWT strictly enforces this RULE. If you try and access an SWT object from outside the UI-thread, you get the exception “org.eclipse.swt.SWTException: Invalid thread access”.

The FOLLOWING code sets the text of a label from a background thread and waits for the operation to COMPLETE:

display.syncExec( new RUNNABLE()

{

public void run(){ label.setText(text);

}

});

SWT implements a single-threaded UI model often called apartment threading. In this model, only the UI-thread can invoke UI operations. SWT strictly enforces this rule. If you try and access an SWT object from outside the UI-thread, you get the exception “org.eclipse.swt.SWTException: Invalid thread access”.

The following code sets the text of a label from a background thread and waits for the operation to complete:

display.syncExec( new Runnable()

{

public void run(){ label.setText(text);

}

});



Discussion

No Comment Found