DebuggerStepThrough,DebuggerHidden不能在async

编程入门 行业动态 更新时间:2024-10-28 18:26:55
本文介绍了DebuggerStepThrough,DebuggerHidden不能在async-await方法中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当您打开抛出异常时中断 DebuggerStepThrough 属性(或 DebuggerHidden )。

When you turn on the "Break when an exception is thrown" feature in the Visual Studio debugger it breaks everywhere for selected exception types. The way to tell it not to break in a specific method is to decorate these methods with DebuggerStepThrough attribute (or DebuggerHidden).

这个显然 ,因为某些原因不适用于 async 方法。 这是一个再现问题的片段。即使标记有属性,调试器将中断 TestAsync 内部 $ c> test as excepted(它们之间的唯一区别是第一个标有 async 关键字):

This, evidently, doesn't work for an async method for some reason. Here's a snippet that reproduces the issue. The debugger will break inside the TestAsync even though it's marked with the attributes and it will not break inside Test as excepted ( the only difference between them is the first is marked with the async keyword):

public class Attributes { public async Task Run() { await TestAsync(); await Test(); } [DebuggerHidden] [DebuggerStepThrough] public async Task TestAsync() { try { throw new Exception("Async"); } catch { } await Task.Delay(100); } [DebuggerHidden] [DebuggerStepThrough] public Task Test() { try { throw new Exception("sync"); } catch { } return Task.Delay(100); } }

那么这个行为是为了吗?是bug吗有没有解决方法?

So, is this behavior intended? Is it a bug? Is there a workaround?

推荐答案

属性与async / await不兼容,因为异步方法在盖子下重写 - 属性不遵循。有关类似的情况,请参阅 stackoverflow/a/22412597/495262 。

Attributes don't play well with async/await since async methods get re-written under the covers--and the attributes do not follow. See stackoverflow/a/22412597/495262 for a similar situation.

更多推荐

DebuggerStepThrough,DebuggerHidden不能在async

本文发布于:2023-11-04 00:24:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556460.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:能在   DebuggerStepThrough   DebuggerHidden   async

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!