Change model from endless running background thread

As in the documentation suggested I tried to use a Task.Backgroundable (Progress indicators page). Since I make changes to the model I use an undoable action and made the following behavior method in my root node for testing:
public void increment(node<RootFile> selfReference) { 
  final node<RootFile> finalNode = selfReference; 
  Project project = ProjectHelper.toIdeaProject(ProjectHelper.getProject(finalNode.model/.getRepository())); 
  Task.Backgroundable backgrounable = new Task.Backgroundable(project, "My task", false) { 
    public void run(@NotNull() ProgressIndicator p0) { 
      final CyclicBarrier barrier = new CyclicBarrier(2); 
      finalNode.model/.getRepository().getModelAccess().executeCommandInEDT(new Runnable() { 
        public void run() { 
          try { 
            while (finalNode.i < 100) { 
              finalNode.i += 1; 
            } 
          } finally { 
            finalNode.block(barrier); 
          } 
        } 
      }); 
      finalNode.block(barrier); 
       
    } 
  }; 
  ApplicationManager.getApplication().invokeLater({ => ProgressManager.getInstance().run(backgrounable); }); 
}             

public void block(CyclicBarrier barrier) { 
  try { 
    barrier.await(); 
  } catch (BrokenBarrierException e) { 
    <no statements> 
  } catch (InterruptedException e) { 
    <no statements> 
  } 
}
       
prettyPrint();
Any ideas why the field i is not getting updated?
Thanks,
fxlex

Please sign in to leave a comment.