RunResult<T> () { Application application = ApplicationManager.getApplication(); boolean dispatchThread = application.isDispatchThread(); if (!dispatchThread && application.isReadAccessAllowed()) { throw new IllegalStateException("Must not start write action from within read action in the other thread - deadlock is coming"); } final RunResult<T> result = new RunResult<>(this); if (dispatchThread) { performWriteCommandAction(result); } else { try { ApplicationManager.getApplication().invokeAndWait(() -> performWriteCommandAction(result)); } catch (ProcessCanceledException ignored) { } } return result; }