10 Things Silverlight Devs Need to Know About the Windows Runtime: Listing 2.

Using async in a WinRT app.

public async void SearchBtn_Click(object sender, RoutedEventArgs e)
  {
    // Retrieve Topic to Search for from WaterMarkTextBox
    string topic = txtSearchTopic.Text;
    // Construct Digg REST URL
    string diggUrl = String.Format(
      "http://services.digg.com/search/stories?query={0}&appkey=http://www.scottgu.com", 
      topic);

    // Initiate Async Network call to Digg
    var client = new HttpClient();
    var response = new HttpResponseMessage();

    //Get response
    response = await client.GetAsync(new Uri(diggUrl));
    Task <string > responseString = response.Content.ReadAsStringAsync();
    string result = await responseString;

    // Call a Method that parses the XML data  
    DisplayStories(result);
  }

About the Author

Michael Crump is a product manager that works at Microsoft on the Azure platform. He is a is a developer, blogger and speaker of topics relating to cloud development. He’s passionate about helping developers understand the benefits of the cloud in a no-nonsense way. You can reach him on Twitter at mbcrump or by following his blog at michaelcrump.net.

comments powered by Disqus

Featured

  • What's New in Visual Studio 2019 v16.5 Preview 2

    The second preview of Visual Studio 2019 v16.5 has arrived with improvements across the flagship IDE, including the core experience and different development areas such as C++, Python, web, mobile and so on.

  • C# Shows Strong in Tech Skills Reports

    Microsoft's C# programming language continues to show strong in tech industry skills reports, with the most recent examples coming from a skills testing company and a training company.

  • Color Shards

    Sharing Data and Splitting Components in Blazor

    ASP.NET Core Version 3.1 has at least two major changes that you'll want to take advantage of. Well, Peter thinks you will. Depending on your background, your response to one of them may be a resounding “meh.”

  • Architecture Small Graphic

    Microsoft Ships Preview SDK, Guidance for New Dual-Screen Mobile Era

    Microsoft announced a new SDK and developer guidance for dealing with the new dual-screen mobile era, ushered in by the advent of ultra-portable devices such as the Surface Duo.

  • How to Create a Machine Learning Decision Tree Classifier Using C#

    After earlier explaining how to compute disorder and split data in his exploration of machine learning decision tree classifiers, resident data scientist Dr. James McCaffrey of Microsoft Research now shows how to use the splitting and disorder code to create a working decision tree classifier.

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events