Take a look at SubMonitor .
void doSomething(IProgressMonitor monitor) {
Technical details aside, here's how I do it:
- Your usual job is 100;
- set the initial work 200;
- The increment works as needed when you progress, believing that the total work should be 100;
- when the work is completed, inform about its completion.
This has the following effects:
- on a regular work item that takes 100 units, it ends very quickly after 50% progress;
- on a long work item, it ends with a good steady progress.
This is better than faster than the user expects, and does not seem to be stuck for a long time.
For bonus points, if / when the detected potentially long subtask is fast enough, still increase the progress by a large amount. This avoids the transition from 50% to completion.
source share