void ( @NotNull final ProgressIndicator indicator, @NotNull Disposable parentDisposable, @NotNull final Runnable action ) { Disposable disposable = Disposer.newDisposable(); Disposer.register(parentDisposable, disposable); ApplicationListener listener = new ApplicationListener() { @Override public void beforeWriteActionStart(@NotNull Object action) { indicator.cancel(); } }; final Application application = ApplicationManager.getApplication(); try { application.addApplicationListener(listener, disposable); ProgressManager.getInstance().runProcess(() -> application.runReadAction(action), indicator); } finally { Disposer.dispose(disposable); } }