ProgressBar while doing calculations and loading

Hi,

My app is required to load some data (from the settings) and do calculations on that data.  Currently my app will automatically load the data in the "onStart" function, which means that for larger datasets, it takes upwards of 30-40 seconds to load and do all the calculations, and more significantly, the user is not presented with any splash screen or progress bar indicating it is in fact working, leading users to believe it may not be working or doing anything at all.  So, I can move the loading procedures into a subprocedure, which will run when the user selects a menu option 'Load Data'.  The problem remains, however, that if the loading process takes more than 5-10 seconds, there is little other feedback provided to the user during this time.  The app can display a small text string "loading" but I would like it to display a 'busy' ProgressBar

-------

My Goal is --   When the user selects 'Load Data' option, my app initiates the below processes--

- The screen displays a ProgressBar BehaviorDelegate ('busy' option)

- (beginning and continuing as the ProgressBar is 'busy') The app conducts loading procedures/calculations**

- If user presses 'back', it will terminate the loading procedures/calculations and pop the ProgressBar BehaviorDelegate 

-------

**I'm not exactly sure how to code the loading procedures/calculations.  With enough data in the settings, the total mass of calculations could trip the watchdog (ie too many calculations), so I have divided it into different work segments.  I am thinking of using a state variable and having a function which conducts the calculations not all at once, lowering risk of tripping watchdog.

// global variable, or could even implement as parameter for below function
var state = 0;

loadData() {
    if (state == 0) {
        // do 1st segment of procedures/calculations
        state += 1;
    } else if (state == 1) {
        // do 2nd segment of procedures/calculations
        state += 1;
    } else if (state == 2) {
        /// ... and so on
        // finished with procedures/calculations
    }
}

The separate segments of the procedures/calculations take different times to complete, and some of them I cannot break down into smaller components, therefore I would prefer the ProgressBar continue to display 'busy' even while the calculations are taking place.  Or maybe it makes more sense to display a "percentage complete" ProgressBar, rather than a "busy" so then, the user can at least see which segment is ongoing. 

But I am still unsure how to code the ProgressBar piece.  Would it work to call this loadData function from inside the initialize() function of the progressBar?  Since some of the segments last several seconds, it doesn't make sense to me, to call this loadData function every second, as in tie it to a timer.  (But maybe it would work - to tie the execution of this function to a timer so it checks it every second, if it's not complete with previous calculations?)

-------

#TLDR...

I know I can send it "busy" command, and change the text displayed, but I'm concerned that if my calculations take too long, it will not update the animation of the 'busy' progress bar.  So I'm more curious on HOW TO ORGANIZE THE CODE inside or outside the ProgressBar BehaviorDelegate, so it can complete the calculations, update the ProgressBar 'busy' animation, and also accept Back input and not appear unresponsive while all this is going on.

Thanks in advance for any help!

  • If you're doing things that take 30-40 seconds, you could very likely get stopped by the watchdog timer, so you want to split things up so you are returning to the VM often enough.

  • ...hence the division into different segments of processing.  would you recommend I include something like the following in the ProgressBar initialize function?  And would it encounter errors if any one step took longer than a few seconds to complete?  I will try this next

                timer.start( method(:loadData), 2000, true );
    

  • Depending on what all you are doing, "a few seconds" could trigger the watchdog.  Have you looked at the progressbar sample in the SDK?

  • I have examined the sample. I'm just not sure where to put the execution of the processing code, since each segment of my processing code doesn't last the same amount of time.  (The progress bar sample is a watchface and not an app, and it provides an example for how to show a progress bar, not how to incorporate it into a loading function for an app)  I have tested the code and have high confidence that for watches it will not trigger the watchdog, but without a progressbar view there is no feedback provided to the user to indicate it is working.    ..thanks I will try the timer option