C# 在调试/单步执行中检查变量时函数评估超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9729320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 08:36:47  来源:igfitidea点击:

Function evaluation timed out when examining variables in debug/stepping through

c#.netvisual-studio-2010

提问by GurdeepS

When debugging/stepping through code, and I try to examine a variable in the watch, I get errors for every inner-variable stating function evaluation timed out.

在调试/单步执行代码时,当我尝试检查手表中的变量时,我收到每个内部变量声明函数评估超时的错误。

Does anyone know why this is and how to avoid it? As it impacts my ability to debug code.

有谁知道这是为什么以及如何避免它?因为它会影响我调试代码的能力。

This is within VS2010 Premium.

这是在 VS2010 Premium 中。

采纳答案by JaredPar

The most likely cause of this problem is an implicit evaluation of a property or ToStringmethod which causes an issue with the CLR evaluation thread. To verify this turn off implicit evaluation.

此问题最可能的原因是对属性或ToString方法的隐式评估,这会导致 CLR 评估线程出现问题。要验证这一点,请关闭隐式评估。

  • Tools -> Options
  • Debugging
  • Uncheck "Enable property evaluation and other implicit function calls"
  • 工具 -> 选项
  • 调试
  • 取消选中“启用属性评估和其他隐式函数调用”

Then restart your scenario and see if it works.

然后重新启动您的场景,看看它是否有效。

回答by Yaur

Visual studio executes the property getter to get its value, if it takes a long time either because its doing something expensive you get this error. consider:

Visual Studio 执行属性 getter 来获取它的值,如果它需要很长时间或者因为它做了一些昂贵的事情你会得到这个错误。考虑:

public class foo
{
    private object lockObject = new object();
    public int bar
    {
        get
        {
             lock(lockObject){
                return 42;
             }
         }
     }
     public int aMethod()
     {
         lock(lockObject)
         {
             var a = this.bar;
             return a*2;   //insert a break point here
          }
      }
}

If you add a break point on the return statement in aMethod the debugger will not be able to evaluate the bar property, because doing so requires that it acquires the lock object, but it won't be able to do so because the program will hold that lock forever while the break point is active

如果在 aMethod 中的 return 语句上添加断点,调试器将无法评估 bar 属性,因为这样做需要它获取锁定对象,但它不能这样做,因为程序将持有在断点处于活动状态时永远锁定