How to Make the total work of SubMonitor as IProgressMonitor.UNKNOWN in eclipse RCP?

I have created SubMonitor by SubMonitor.convert(monitor,IProgressMonitor.UNKNOWN ). Even though i am providing the total work as UNKNOWN, internally it assigns 1000 as total number of ticks(refer SubMonitor.java). how to make the total work as UNKNOWN in this case?

Answer

SubMonitor doesn’t really support unknown progress.

You can either stick with just using IProgressMonitor and not converting or you can use code like this:

void unknownProgress(IProgressMonitor monitor)
{
    SubMonitor subMonitor = SubMonitor.convert(monitor);
    while (hasMore())
     {
        // Use 1% of the remaining space for each iteration
        processNext(subMonitor.setWorkRemaining(100).split(1));
     }
}

as suggested in this article.

Leave a Reply

Your email address will not be published. Required fields are marked *