Reputation: 1557
I have a page that runs a large amount of code to prepare the page and layout of the page for the user.
It only needs to be used once in a blue moon. But when it does, it's about three seconds of wait for the user.
Apparently, Microsoft only allows a 2 or less second wait. Daaaaang.
I've optimized and optimized the code, and there's no way around it: the code is as fast as it can be. So naturally, I set out to make a loader.
I tried to update several controls, but thanks to the UI thread being frozen, they didn't work.
I searched and searched and searched, and found this, which was confusing and didn't really help, partly because of WP7's version of C# and partly because of me being a beginner at C#.
How can I make a loader that works while the UI thread is frozen?
Upvotes: 0
Views: 3088
Reputation: 5847
The Silverlight Toolkit For Windows Phone introduces the PerformanceProgressBar
, "which uses the compositor thread exclusively for animation, instead of the UI (user interface) thread" as described in this WindowsPhone Geek article. This should help you with the freezing UI.
As of the parallel execution (suggested by Merlyn), I'd suggest the QueueUserWorkItem method to execute code in a separate thread over the BackgroundWorker
, leaving the UI thread active for UI updates, but as described in the article, you will need to use Dispatcher.BeginInvoke
to update your UI from there.
Upvotes: 2
Reputation: 59111
You can try using the BackgroundWorker
class. That page has a tutorial for how to use it.
See this question and my answer for another tutorial. Though not Windows Phone 7 specific, it still has to do with updating the UI while waiting for a task to complete:
Here's a Windows Phone 7 specific tutorial for using the BackgroundWorker
:
Upvotes: 1