Freigeben über


WP7 Perf Tip #2: Know your ProgressBar

Take Away's:

  1. Do not use the built in ProgressBar straight up, use Jeff's template 
  2. When you're done with an indeterminate ProgressBar, make sure to toggle IsIndeterminate to False and Collapse the bar
  3. General: Always make sure to stop animations / remove animating controls when they're no longer needed 

Some Background:

Due to a bunch of different reasons the shipping ProgressBar control is suboptimal and will actually be UI thread bound - meaning that if your UI thread is stuck working, your ProgressBar will be stuck as well. Not a great situation for a ProgressBar, huh?

That said, we're not leaving you high and dry. Jeff Wilcox has a great solution which changes the template for the ProgressBar to only run on the Render thread - meaning that it will continue ticking, even when you're doing your heavy loading work on the UI thread. That said, it still comes with a gotcha - don't forget to set IsIndeterminate to False and to Collapse the bar once your done (instead of just setting Visibility to Hidden) so that the ProgressBar doesn't continue to tick in the background, eating up Render thread cycles.

As a general rule, highlighted especially by the ProgressBar, you should always make sure to stop animations (not pause) and remove / collapse animating controls when they're no longer needed.

Remember:  just because you can't see a animation / control doesn't mean that it isn't there doing work.