Sunday, February 17, 2008

How to use the progressmonitor

This notes were in the udig developers manual, but they do not seem to exist any more (perhaps I just can't find them :)). However, before they get lost from the google cache (which is were I found them), I past them here for convenience:



* Always start the progress monitor and do at least 1 bit of work. For example:

monitor.beginTask("Working", 4);
monitor.worked(1);


* Always finish started job.

try{
monitor.beginTask("Working", 4);
monitor.worked(1);
// some work
}finally{
monitor.done();
}


* Make use of SubProgressMonitor if sending the monitor to another method:

try{
monitor.beginTask("Working", 8);
monitor.worked(1);

SubProgressMonitor sub=new SubProgressMonitor(monitor, 3);
doSomeWork(sub);
sub.done(); // don't forget to make sure the sub monitor is done

sub=new SubProgressMonitor(monitor, 3);
doSomeMoreWork(sub);
sub.done(); // don't forget to make sure the sub monitor is done (callee might not use it)

}finally{
monitor.done();
}
Post a Comment