C# async,await
class Program
{
static void Main(string[] args)
{
(new Program()).MyMethodAsync();
Console.ReadLine();
}
public async Task MyMethodAsync()
{
Task<int> task = AccessTheWebAsync();
int result = await task;
Console.WriteLine(result);
}
async Task<int> AccessTheWebAsync()
{
HttpClient client = new HttpClient();
Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com");
string urlContents = await getStringTask;
return urlContents.Length;
}
}