diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManager.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManager.java index e9b35fe2010..6d1250edce2 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManager.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/progress/ProgressManager.java @@ -844,21 +844,28 @@ public void busyCursorWhile(final IRunnableWithProgress runnable) */ private void busyCursorWhile(Runnable dialogWaitRunnable, ProgressMonitorJobsDialog dialog) { // Create the job that will open the dialog after a delay. - scheduleProgressMonitorJob(dialog); - final Display display = PlatformUI.getWorkbench().getDisplay(); - if (display == null) { - return; + Job showDialogJob = scheduleProgressMonitorJob(dialog); + try { + final Display display = PlatformUI.getWorkbench().getDisplay(); + if (display == null) { + return; + } + // Show a busy cursor until the dialog opens. + BusyIndicator.showWhile(display, dialogWaitRunnable); + } finally { + // In case the dialog hasn't popped up yet, cancel it so it doesn't pop up after + // the operation finishes or unwinds with an exception. + showDialogJob.cancel(); } - // Show a busy cursor until the dialog opens. - BusyIndicator.showWhile(display, dialogWaitRunnable); } /** * Schedules the job that will open the progress monitor dialog. * * @param dialog the dialog to open + * @return the job that was scheduled to open the dialog */ - private void scheduleProgressMonitorJob(final ProgressMonitorJobsDialog dialog) { + private Job scheduleProgressMonitorJob(final ProgressMonitorJobsDialog dialog) { final WorkbenchJob updateJob = new WorkbenchJob(ProgressMessages.ProgressManager_openJobName) { @Override public IStatus runInUIThread(IProgressMonitor monitor) { @@ -871,7 +878,7 @@ public IStatus runInUIThread(IProgressMonitor monitor) { }; updateJob.setSystem(true); updateJob.schedule(getLongOperationTime()); - + return updateJob; } /** @@ -974,11 +981,19 @@ public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable // Backward compatible code. final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog( ProgressManagerUtil.getDefaultParent()); - dialog.setOpenOnRun(false); - if (!shouldRunInBackground()) { - scheduleProgressMonitorJob(dialog); + if (shouldRunInBackground()) { + dialog.setOpenOnRun(false); + dialog.run(fork, cancelable, runnable); + } else { + Job showDialogJob = scheduleProgressMonitorJob(dialog); + try { + dialog.run(fork, cancelable, runnable); + } finally { + // In case the dialog hasn't popped up yet, cancel it so it doesn't pop up after + // the operation finishes or unwinds with an exception. + showDialogJob.cancel(); + } } - dialog.run(fork, cancelable, runnable); return; }