In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to make asynchronous calls in Windows 8 application development. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
In order not to affect the interactive experience between users and applications, developers usually use asynchronous invocation technology, so that more complex logical operations are carried out asynchronously, and users can continue to use the application without waiting for response.
Demonstrate how to use asynchronous programming in Windows 8 applications through a simple example. First, let's write a "Get Blogs" button that you can click to get a list of blogs from Windows Blog. Of course, the process of getting blog information is done asynchronously, and in order to test that users can still interact with the application, we design a "Change Text" to modify the content of the waitingText.
Code
Next, add a Click event to the "Get Blogs" button. GetBlogs_Click differs from previous Click events in that there is an extra async keyword. Seeing Async indicates that the following should be implemented through asynchronous methods. The blog content is obtained through SyndicationClient.RetrieveFeedAsync in the method, and the application is told to invoke the asynchronous operation through the await operator without affecting the normal user interaction. If the asynchronous call is not used, the user can only wait for all the blog content to be loaded before continuing to use the application.
Private async void getBlogs_Click (object sender, RoutedEventArgs e) {waitingText.Text = "Loading Blogs..."; SyndicationClient client = new SyndicationClient (); client.BypassCacheOnRetrieve = true; Uri feedUri = new Uri ("http://blogs.windows.com/windows/b/bloggingwindows/atom.aspx"); try {SyndicationFeed feed = await client.RetrieveFeedAsync (feedUri); ObservableCollection blogData = new ObservableCollection ()) ListTitle.Text = feed.Title.Text Foreach (SyndicationItem item in feed.Items) {blogData.Add (new BlogItem () {Author = item.Authors [0] .Name.ToString () PubDate = item.PublishedDate.Year.ToString () + "/" + item.PublishedDate.Month.ToString () + "/" + item.PublishedDate.Day.ToString (), Title = item.Title.Text}) } blogList.ItemsSource = blogData; waitingText.Text = "Completed!";} catch (Exception ex) {waitingText.Text = "Can't load the page:" + ex.ToString ();}}
Demo
The running program clicks the "Get Blogs" button, and now the application has obtained the Blog content asynchronously, so we can click "Change Text" to verify that the user can continue to use the other features that should be used.
After clicking "Get Blogs", there will be "Loading Blogs..." Indicating that the asynchronous call has been started
Click "Change Text" before getting the blog content, and the text will change to "Please Waiting …" Indicating that the user can still interact with the application when it is called asynchronously
After the asynchronous call is completed, the text part is updated to "Completed!".
At this point, the development of asynchronous invocation is complete. This article is only one type of asynchronous invocation, of course, there are many other types of API available, and include C #, VB, JS multi-language development.
On how to carry out Windows 8 application development of asynchronous calls to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.