The task parallel library is one of the good additions to Windows Phone development. However, using the Task Parallel Library within the Windows Phone application can become tricky.

While developing an app, I found that when you await on a Tasks say a Web client download in the Loaded event of a page. Now when the users moves out of the page to another one, the Web client call can complete in the background. Since you were awaiting on this background call, the code after the await may proceed, resulting in an un-expected scenario.

This was the same problem I face in my app. I was loading some data on the loaded event of a page in my app. When the data load call failed due to whatever reason , I displayed a popup saying “Sorry, We could not find any data for you”. Now when I navigated to this page and quickly navigated back multiple times, many data calls were made.

Now assuming all the calls failed one after another, the user was shown these annoying popups out of the blue.

The bottom line, when using tasks to download data, make sure that you terminate such calls when a user navigates away from the page.

I might post some additional details and my final resolution to the problem later.

Hope this helps.


Share your thoughts

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s