简体   繁体   English

调试异步堆栈的预期方法-发生了什么?

[英]Expected ways to debug an async stack - what's going on?

I have a method that inconsistently fails, therefore I can't replicate with any certainty. 我有一个始终失败的方法,因此无法确定地复制。

I've captured the stacktrace and exception of one of these failures (below). 我已经捕获了堆栈跟踪和这些故障之一的异常(如下)。 Usually this would just be a case of exploring the stack to understand how the code got to it's current state. 通常,这只是探索堆栈以了解代码如何达到当前状态的一种情况。

However since the method is marked async the stack trace makes no sense . 但是,由于该方法被标记为异步,因此堆栈跟踪没有任何意义

I'd love to be able to check what the various variables were set to. 我希望能够检查各种变量设置为什么。 Does anyone have any hints / tips / proven ways of working with an async stack so I can get the root of my issue? 任何人都没有任何使用异步堆栈的提示/技巧/行之有效的方法,以便让我了解问题的根源吗?

异步堆栈跟踪

Object reference not set to an instance of an object.

You may use Async Diagnostics library together with PostSharp to get logical stack. 您可以将Async Diagnostics库与PostSharp一起使用以获取逻辑堆栈。 See the article Async Diagnostics blog post 请参阅文章“ 异步诊断”博客文章

The stacktrace is usually not usable in async code because it will just tell you that the call to some async method has fail. stacktrace通常在异步代码中不可用,因为它只会告诉您对某些异步方法的调用已失败。 Neither is the debug step by step, because if it is hard to reproduce, it is probably a timing error and you will never reproduce it in debug. 调试也不会一步一步进行,因为如果很难重现,则很可能是计时错误,并且您永远都不会在调试中重现它。

Instead use try/catch and check the aggregate exception. 而是使用try / catch并检查聚合异常。 Be sure that your method return a Task, and that this Task is awaited, or you won't catch anything. 确保您的方法返回一个Task,并且等待该Task,否则您将不会捕获任何东西。

I think this MSDN documentation will help you to catch your error correctly. 我认为此MSDN文档将帮助您正确捕获错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM