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;
}
}
时间: 2024-10-29 03:07:48