我是新手,所以请多多包涵。我正在调试并遇到问题:
var response = await client.GetAsync(uri);
我已经编辑了问题,使其符合最小、完整和可验证的示例。
我在这条语句上跨过调试器以便移动到下一条语句但是由于我仍然不知道的原因,调试器似乎丢失并且无法恢复。
每次我点击 await
调用并跳过时,它每次都会发生。调试器断点就消失了。
全部代码如下:
public class App : Application // superclass new in 1.3
{
public App ()
{
MainPage = new PinPage { Title = "Pins", Icon = "marker.png" };
}
}
public class PinPage : ContentPage
{
private async Task FetchDataAsync()
{
HttpClient client = new HttpClient();
string resultUrl = "http://myuser.gtempurl.com/Service1.svc/GetLocations";
var uri = new Uri(string.Format(resultUrl, string.Empty));
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
var obj = JsonConvert.DeserializeObject(content);
}
}
public PinPage ()
{
FetchDataAsync().GetAwaiter().GetResult();
}
}
WCF 服务不是问题。它发布在公共(public)服务器上,因此始终可用。我从浏览器调用它,它返回预期的字符串。
我正在使用 VS2017,它在 Android 模拟器中进行调试。
这是断点命中语句时的屏幕截图:
最佳答案
it does not move to the next line. No other line of code is highlighted yellow, no timeout, nothing.
这听起来像是一个僵局。由于这是一个 UI 应用程序,因此请进一步检查您的调用堆栈是否有任何阻塞调用,例如 Wait()
、Result
或 GetAwaiter().GetResult()
。这些可以deadlock if called from the UI thread .
正确的解决方案是将它们更改为await
;换句话说,使用 async
all the way .
关于c# - 为什么我的调试器似乎卡在 await 语句中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54526935/