|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionEverybody knows the frustration caused by a new progress bar popping up and starting from 0% just after the previous one reached 100%. This annoyance is caused by several consecutive subroutines providing independent progress feedback. Collapsing these isolated progress bars into one bar running from 0 to 100% can be a nasty problem. In this article, an object-oriented approach is presented that provides an elegant and transparent solution to this problem. BackgroundIn complex software packages, there are often multiple lengthy tasks that provide progress feedback. A single user action could lead to a number of such tasks being executed, typically resulting in several consecutive instances of progress running from 0 to 100%. It is desirable to collapse the isolated instances of progress feedback into one overall instance of feedback running from 0 to 100%. This willl give the user a good notion of how much of the overall task has been finished and how much is left. It is possible to solve this problem by hard-coding the progress range into every function or by passing the current progress as parameters to each function. However, the first solution is not very flexible (consider calling the same subroutines in a different order or different context) and the latter poses constraints to your code. Therefore this article presents a transparent and flexible solution to the above-described problem. We introduce a Using the CodeConsider a simple traditional class for progress feedback, void A()
{
CTraditionalProgress myProgress;
myProgress.Set(0);
B(); //call function B
myProgress.Set(60);
C(); //call function C
myProgress.Set(100);
}
It is very simple to imagine how the code of Now suppose that functions One small adjustment to our code concerns replacing the void A()
{
CProgress myProgress;
myProgress.SetRange(0.60);
B(); //call function B
myProgress.SetRange(0.40);
C(); //call function C
}
void B()
{
CProgress myProgress;
myProgress.SetRange(0.20);
// Do something, estimated duration 20% of time for function B()
for (int n=0; n < 80; n++) {
myProgress.SetRange(0.01);
// Do something, estimated duration 1%
}
}
The progress feedback of function
Points of InterestIf you are interested in the inner workings of the collapsing mechanism, have a look at the sample code and at the PDF article that is attached in the ZIP file. The main trick is the fact that each History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||