0

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!

lifeline2
  • 69
  • 1
  • 15
  • Well this should fail to run completely in Eclipse Mars because the SubMonitor class does not exist in that release. I have always found that the progress monitor cancel is very slow to operate. – greg-449 Sep 30 '16 at 14:04
  • Sorry I have Luna at target. So the the SubMonitor must be coming from Luna only. Let me edit my question than.. Thanks for the input, greg-449 – lifeline2 Oct 01 '16 at 06:21

1 Answers1

0

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

lifeline2
  • 69
  • 1
  • 15