首页 > 解决方案 > Automatically break debugger on Debug.Assert fail

问题描述

This may seem like a silly question, but no amount of Googling will give me the answer. In C#, when using the Debug.Assert class, a failure causes a MessageBox to show. Pressing "Retry" goes to the call site in the debugger. Is there any way to do so automatically i.e. go straight to the call site (skip pressing "Retry" every time?)

标签: .netvisual-studiosystem.diagnostics

解决方案


用于System.Diagnostics.Debugger.Break();暂停进程的执行,就像遇到调试器断点一样:

void DebugAssert(bool condition)
{
  if(!condition)
    System.Diagnostics.Debugger.Break();
}

推荐阅读