c# - 我应该在 Debugger.Break 或 Debug.WriteLine 之前检查 Debugger.IsAttached 吗?

标签 c# .net debugging

我想知道是否应该在调用其他 Debug 和 Debugger 函数之前调用 if(Debugger.IsAttached)

if(Debugger.IsAttached) { Debugger.Break(); }

对比

Debugger.Break() // Without checking if Debugger is actually attached

最佳答案

这取决于您调用 Break() 方法的原因。根据documentation :

If no debugger is attached, users are asked if they want to attach a debugger.

如果您不想打扰当前没有调试的用户,那么您应该先测试附件。如果您不在乎(或者实际上想要提示),则不要检查。

关于c# - 我应该在 Debugger.Break 或 Debug.WriteLine 之前检查 Debugger.IsAttached 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7324873/

相关文章:

c# - XNA C# 2D 平铺引擎

c++ - 如果我不使用 <iostream> 的功能,我可以避免包含它吗?

ios - 如何追踪 "incorrect checksum for freed object"

c++ - 在 Eclipse 中使用 GDB 时出错 : "Command ' -list-features' is timed out"

c# - 鼠标光标处的 UWP 位置浮出控件

c# - 将字段传递给函数以对该字段进行排序

c# - 鼠标滚轮输入无法统一识别

c# - 为什么 ForEach 方法只适用于列表

.net - 在构建服务器上运行 Roslyn 代码分析器

c# - 如何检查 Windows 文件是否可读/可写?