void (final @NotNull WorkerThreadRequest threadRequest) { try { DumbService.getInstance(myProject).runWithAlternativeResolveEnabled(() -> ProgressManager.getInstance().runProcess(() -> { while (true) { try { if (threadRequest.isStopRequested()) { break; } final WorkerThreadRequest currentRequest = getCurrentRequest(); if (currentRequest != threadRequest) { String message = "Expected " + threadRequest + " instead of " + currentRequest + " closed=" + myEvents.isClosed(); reportCommandError(new IllegalStateException(message)); break; // ensure events are processed by one thread at a time } processEvent(myEvents.get()); } catch (VMDisconnectedException | EventQueueClosedException ignored) { break; } catch (ProcessCanceledException ignored) { } catch (CompletionException e) { if (e.getCause() instanceof VMDisconnectedException) { break; } reportCommandError(e); } catch (RuntimeException e) { if (e.getCause() instanceof InterruptedException) { break; } reportCommandError(e); } catch (Throwable e) { reportCommandError(e); } } }, threadRequest.myProgressIndicator)); } finally { // ensure that all scheduled events are processed if (threadRequest == getCurrentRequest()) { processRemaining(); } LOG.debug("Request " + this + " exited"); } }