GetStringAsync() Method in HttpClient Class

A quick introduction is provided on the System.Net.Http.HttpClient class and System.Threading.Tasks.Task<T> class, which can be used to play with asynchronous operations.

To practice the Async feature of C# 5, we can use the System.Net.Http.HttpClient class. Here is some basic information about the HttpClient class.

System.Net.Http.HttpClient is a .NET Framework class that allows us to send HTTP requests to remote Web sites and receive HTTP responses in asynchronous operations. Here are some basic methods supported in the HttpClient class:

As you can see, these Get*Async() methods return a generic class object, System.Threading.Tasks.Task<T>. So we need to learn some details of the Task<T> class.

System.Threading.Tasks.Task<T> a system class representing an asynchronous operation that returns a result when the operation is completed. Here are some basic properties and methods supported in the Task<T> class:

With these two classes, we can start to play with asynchronous operations with GetStringAsync(String) method provided in the HttpClient class. See the next tutorial for examples.

Table of Contents

 About This Book

 Introduction of C# (C Sharp)

 Data Type and Variables

 Logical Expressions and Conditional Statements

 Arrays and Loop Statements

 Data Type Features

 Floating-Point Data Types

 Passing Parameters to Methods

 Execution Environment Class

 Visual C# 2010 Express Edition

 Class Features

 C# Compiler and Intermediate Language

 Compiling C# Source Code Files

 MSBuild - Microsoft Build Engine

 Memory Usages of Processes

 Multithreading in C#

Async Feature from C# 5

 What Is Async Feature?

GetStringAsync() Method in HttpClient Class

 GetStringAsync() Method Example Program

 Watching Asynchronous Operation Execution Status

 "await" Expression and Child Thread

 "await" Expression Thread Example

 "async" Function Example

 System.IO.FileInfo Class

 System.Diagnostics.FileVersionInfo Class

 WPF - Windows Presentation Foundation

 Partial Classes and Partial Methods

 Archived Tutorials

 References

 Full Version in PDF/ePUB