void (Project project) { MavenUtil.invokeLater(project, () -> { final ModalityStateListener listener = new ModalityStateListener() { @Override public void beforeModalityStateChanged(boolean entering, @NotNull Object modalEntity) { if (entering) { suspend(); } else { resume(); } } }; LaterInvocator.addModalityStateListener(listener, this); if (MavenUtil.isInModalContext()) { suspend(); } }); }