How to stop Level Set Plugin after x iterations

I’m using Level Set to refine the ROIs I get from the other part of the code. Sometimes LevelSet fails to coverage and keeps executing for a long period of time. I want to identify the occurrence of such scenario midway. This would not only save a lot of execution time but also make the result much better.

        for (int i = 0; i < rm.getCount() ; i++) {;
        copy.setRoi(rm.getRoi(i));, "Level Sets", "method=[Active Contours] use_level_sets grey_value_threshold=1 distance_threshold=0.50 advection=1.0 propagation=1 curvature=1 grayscale=1 convergence=0.0050 region=outside");