@Override
  public void dispose() {
    SingleTask task = null;

    synchronized (LOCK) {
      closeQueue();

      if (myRunningTask != null) {
        task = myRunningTask;
        myRunningTask = null;
      }
    }

    if (task != null) {
      boolean longTimeOut = !ApplicationManager.getApplication().isDispatchThread() ||
                            ApplicationManager.getApplication().isUnitTestMode();
      try {
        int timeout = longTimeOut ? 1000 : 20;
        task.waitFor(timeout, TimeUnit.MILLISECONDS);
      }
      catch (InterruptedException | ExecutionException e) {
        if (!(e.getCause() instanceof CancellationException)) {
          LOG.debug(e);
        }
      }
      catch (CancellationException ignored) {
      }
      catch (TimeoutException e) {
        if (longTimeOut) LOG.warn(formMessage("Wait time out "), e);
      }
    }
  }
@Override
  public void dispose()