org.eclipse.swt.widgets.Display.readAndDispatch() process the event from the event queue and will return false if more events are not processed. But you probably don't want to use this as it handles the event.
asyncExec(*) is a FIFO queue (although OS graphics events replace asyncExecs), so you could do most of your lengthy op processing and then put the final asyncExec in the queue:
final boolean[] done = new boolean[1]; Runnable r = new Runnable() { public void run() { done[0] = true; } };
In theory, all other asyncExecs generated from your long number will be finished by the time you get to the last.
EDIT : A Potential Another Option
Create your own org.eclipse.core.runtime.jobs.Job and then join() at the end:
public static class RefCountJob extends Job { public RefCountJob() { super("REF_COUNT"); } int count = 0; public void increment() { count++; } public void decrement() { count--; } @Override protected IStatus run(IProgressMonitor monitor) { monitor.beginTask("WAITING", IProgressMonitor.UNKNOWN); while (count > 0) { Thread.sleep(200); monitor.worked(1); } monitor.done(); return Status.OK_STATUS; } }
To use it, increment () it every time you are going to fire events, and decrease them when they are done (you have to make sure that they decrease it no matter which exception is thrown :-)
RefCountJob ref = new RefCountJob(); // ... do stuff, everybody increments and decrements ref ref.increment(); // ... do more stuff ref.increment(); // at the end of your long-running job ref.schedule(); ref.join();
source share