Skip to content

Instantly share code, notes, and snippets.

@sdruskat
Created February 20, 2018 08:35
Show Gist options
  • Save sdruskat/27cd5c19590c86877087facf26113f9b to your computer and use it in GitHub Desktop.
Save sdruskat/27cd5c19590c86877087facf26113f9b to your computer and use it in GitHub Desktop.
A simple example for an Eclipse Job that updates the UI

#Async Eclipse Job Example

  @Inject
	private UISynchronize uiSync;

	public void doSomething() {
		Job j = new Job("Doing work") {

			@Override
			protected IStatus run(IProgressMonitor monitor) {

				try {
					// Do something

					uiSync.asyncExec(() -> {
						// Do something long-running that updates the UI
					});

				}
				catch (Exception e) {
					uiSync.asyncExec(() -> {
						MessageDialog.openError(parent.getShell(), "Got error", e.getMessage());
					});
				}
				return Status.OK_STATUS;
			}

		};
		j.setUser(true);
		j.setPriority(Job.LONG);
		j.schedule();
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment