Пример MSDN для async / await - я не могу достичь точки останова после вызова await?
В примере MSDN с async / await, почему я не могу достичь точки останова после оператора await?
private static void Main(string[] args)
{
AccessTheWebAsync();
}
private async Task<int> AccessTheWebAsync()
{
// You need to add a reference to System.Net.Http to declare client.
HttpClient client = new HttpClient();
// GetStringAsync returns a Task<string>. That means that when you await the
// task you'll get a string (urlContents).
Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com");
// You can do work here that doesn't rely on the string from GetStringAsync.
/*** not relevant here ***/
//DoIndependentWork();
// The await operator suspends AccessTheWebAsync.
// - AccessTheWebAsync can't continue until getStringTask is complete.
// - Meanwhile, control returns to the caller of AccessTheWebAsync.
// - Control resumes here when getStringTask is complete.
// - The await operator then retrieves the string result from getStringTask.
string urlContents = await getStringTask;
// The return statement specifies an integer result.
// Any methods that are awaiting AccessTheWebAsync retrieve the length value.
return urlContents.Length;
}
Насколько я понимаю, await - это конструкция, которая абстрагирует асинхронный поток от разработчика - оставляя его / ее так, как будто он работает синхронно. Другими словами, в приведенном выше коде меня не волнует, как и когдаgetStringTask
Я заканчиваю, я забочусь только о том, чтобы закончить и использовать результаты. Я ожидал бы, что когда-нибудь смогу достичь точки останова после ожидающего звонка.