User Tools

Site Tools


ui_access_from_job

Accessing UI from Background Job

In SWT (Eclipse) the UI can only be access and modified from the main Thread. Everything else results in an error:

org.eclipse.swt.SWTException: Invalid thread access

This can be fixed by synchronizing the with the main thread.

In Eclipse e4 a UISynchronize instance can be injected like this:

@Inject private UISynchronize sync;

This allows us to run something from a background job accessing the UI.

sync.asyncExec(new Runnable() {
				
  @Override
  public void run() {
    // your UI access here
  }
});

ui_access_from_job.txt · Last modified: 2013/12/02 20:02 by mihael