Search code examples
eclipseeclipse-plugineclipse-rcpeclipse-marsxtend

How to cancel progress monitor eclipse4.4


I have below code written in xtend :

void doMyMethod(IProgressMonitor monitor, Collection myCollection) {

    val subMonitor = SubMonitor.convert(monitor, myCollection.size());
    subMonitor.setTaskName("My Task Name...");
    myCollection.forEach [ element |

    if(subMonitor.canceled || monitor.canceled)
    {
        throw new OperationCanceledException
    }

    subMonitor.worked(1)]
 }

Meant to stop the progress monitor when user cancels the progress monitor from UI. But is not working. I am following Using prograess monitor, which says can't use monitor.split in eclipse 4.6. Strangely though if I put a debug point @subMonitor.worked(1) and run the eclipse in debug mode it is working as expected and cancels the monitor if cancels from UI but not working if the debug point is removed. Any idea would be much helpful because I am running short of ideas if debug mode works it should also work without it as well!


Solution

  • I could able to cancel the progress monitor by changing to :

    void doMyMethod(IProgressMonitor monitor, Collection myCollection) {
    
    monitor.beginTask(("My Task Name...", myCollection.size());
    
    myCollection.forEach [ element |
    
    if(subMonitor.canceled || monitor.canceled)
    {
        throw new OperationCanceledException
    }
    subMonitor.worked(1)] }
    

    thanks