void (@NotNull Project project) { final String projectPath = getProjectPath(project); ProgressManager.getInstance().run(new Task.Modal(project, JavaCompilerBundle.message("progress.title.cancelling.running.builds"), false) { @Override public void run(@NotNull ProgressIndicator indicator) { final TaskFuture<?> currentBuild = myBuildsInProgress.get(projectPath); if (currentBuild != null) { currentBuild.cancel(false); } myAutoMakeTask.cancelPendingExecution(); cancelPreloadedBuilds(projectPath); for (TaskFuture<?> future : cancelAutoMakeTasks(project)) { future.waitFor(500, TimeUnit.MILLISECONDS); } if (currentBuild != null) { currentBuild.waitFor(15, TimeUnit.SECONDS); } } }); }