I have written the following (a plain Console application) to test my understanding about async and await in C#.
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Async result: " + getLengthFromWebsiteAsync());
}
public static async Task<int> getLengthFromWebsiteAsync()
{
HttpClient httpClient = new HttpClient();
Task<string> sampleTask = httpClient.GetStringAsync("http://www.adobe.com");
Console.WriteLine("Before the await: ");
int lengthRequired = (await sampleTask).Length;
Console.WriteLine("After the await: " + lengthRequired.ToString());
return lengthRequired;
}
The following is the result that I got upon running:
Before the await:
Async result: System.Threading.Tasks.Task'1[System.Int32]
My question is, isn't the line "After the await: " supposed to show up? Am I on the wrong track in understanding the flow of async/await?