WP7 Perf Tip #2: Know your ProgressBar
- Do not use the built in ProgressBar straight up, use Jeff's template
- When you're done with an indeterminate ProgressBar, make sure to toggle IsIndeterminate to False and Collapse the bar
- General: Always make sure to stop animations / remove animating controls when they're no longer needed
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.