16

我想在短时间内暂时禁用断点,所以我设置了一个条件断点,条件如下:

(global::System.DateTime.Now<new global::System.DateTime(2014,03,28,11,0,0))

当这个断点被击中时,会弹出一个对话框,说

The condition for a breakpoint failed to execute. The condition was 
'(global::System.DateTime.Now<new
global::System.DateTime(2014,03,28,11,0,0))'. The error returned was
'The runtime has refused to evaluate the expression at this time.'. Click
OK to stop at this breakpoint.

为什么运行时拒绝评估表达式?

在不修改调试的源代码的情况下,我可以做些什么来获得所需的行为?

4

2 回答 2

23

从 VS2012 开始,您必须切换到托管兼容模式才能使用条件断点。为什么(抱歉,由于该链接已损坏,因此不再来自 MS 的原因。我添加了指向 archive.org 的链接)以及此处描述的方式:

在-visual-studio-2013 中切换到托管兼容性模式

旧的微软链接,现在死了

archive.org 上的原始 Microsoft 文章

于 2015-05-28T09:51:50.990 回答
-2

据我所知,这是不可能的。你可以做的是使用HitCount

或在代码中使用计时器(如您所愿)进行硬C#编码

#if DEBUG 
  if(System.Diagnostics.Debugger.IsAttached)
     System.Diagnostics.Debugger.Break();
#endif
于 2014-03-28T09:50:32.907 回答