Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ui_access_from_job [2013/12/02 21:02]
ui_access_from_job [2021/04/05 11:23] (current)
Line 1: Line 1:
 +====== 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.
 +
 +<sxh java>
 +sync.asyncExec(new Runnable() {
 +
 +  @Override
 +  public void run() {
 +    // your UI access here
 +  }
 +});
 +</sxh>
 +
 +===== Links =====
 +  * [[http://www.vogella.com/articles/EclipseJobs/article.html | Eclipse Jobs]]
 +
 +{{tag>e4 devel java}}