void (@NotNull ProgressIndicator progressIndicator) { final Semaphore semaphore = new Semaphore(); semaphore.down(); ApplicationManager.getApplication().executeOnPooledThread(() -> { try { myProcessHandler.waitFor(); } finally { semaphore.up(); } }); progressIndicator.setText(ExecutionBundle.message("waiting.for.vm.detach.progress.text")); ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { while (true) { if (progressIndicator.isCanceled() || !progressIndicator.isRunning()) { semaphore.up(); break; } try { //noinspection SynchronizeOnThis synchronized (this) { //noinspection SynchronizeOnThis wait(2000L); } } catch (InterruptedException ignore) { } } } }); semaphore.waitFor(); }