debugging - Xamarin 跳过了一个可等待的方法

标签 debugging asynchronous xamarin xamarin.android async-await

在 WPF 应用程序 (F10) 中,一个可等待的方法会将您带到下一行,但在 xamarin android 项目中,它的行为并非如此(就像我按下了 F5 一样),我不得不在上放置一个断点下一行以便正确调试 - 这太麻烦了 - 。

 async Task SomeMethod()
 {
     await Task.Delay(1000); <--------- Stepping over this line leaves the function.
     int x = 1; <--------- I have to add a breakpoint here.
 }

这是一个错误还是一个功能?

PS:我使用的是 Visual Studio 2017。

最佳答案

确保您的方法是异步的。测试了我的,它在我身边工作。下面的例子:-

  Task.Run(async () =>
      {
        await Task.Delay(1000); 
        int x = 1;
      });

或者
async Task YourMethod
    {
       await Task.Delay(1000); 
       int x = 1;
    }

关于debugging - Xamarin 跳过了一个可等待的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44546657/

相关文章:

JavaScript 异步函数不是非阻塞的

android - "java.exe"以代码 2 退出

ios - 当 iOS 应用程序在 Xamarin 中作为后台时,如何通知我蓝牙连接?

linux - 如何调试 Linux 内核中的页面错误

visual-studio - 如何在 Visual Studio 中的 "Start Debugging"时运行自定义代码并附加到调试器

c# - .NET ConcurrentDictionary GetOrAdd 方法可以调用异步方法吗?

javascript - 为什么 Javascript 异步/等待代码并行运行异步

Xamarin.Forms 自动完成跨平台

c - 如何开始调试?

ios - Xcode 异常断点总是在属性上暂停