On the road Windows Phone (vi) Task Parallel Library

Source: Internet
Author: User

Page load is very card

One of my applications has a page to manage the raw material library, as shown in Figure 1, which is a pivot page with each pivot item listing a class of raw materials. The entire pivot page is tied to a Manageingredientsviewmodel object, each pivot item is bound to a Ingredientgroupviewmodel object, which The Ingredientgroupviewmodel object is created at run time based on data from the raw material library.

Figure 1

The current practice is to load the data through LINQ to SQL in the Manageingredientsviewmodel constructor, and then create the corresponding Ingredientgroupviewmodel object, as shown in code 1. This kind of synchronous loading data is very common and intuitive, but if there is more data and is accompanied by disk or network access, it may cause the page to load very card.

Code 1

I want to load the data asynchronously and load its data only when the user is viewing a pivot item, which ensures that the page remains responsive while avoiding loading redundant data. In this article, we will explore how to implement these effects through the Task Parallel library (tasks Parallel library,tpl) In the context of this application.

Start a task

First, I don't want to load all the data from the start, so replace the previous Code 1 with the following code 2, which is responsible for creating a set of empty Ingredientgroupviewmodel objects. Because the ItemsSource property of the pivot control and the Ingredientgroups property bindings of the Manageingredientsviewmodel object, the pivot control automatically creates an empty set of pivot items.

Code 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.