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

前端 未结 2 1571
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 10:48

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 11:45

    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:

    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

提交回复
热议问题