C# Visual Studio Debugger UI behavior with lock

前端 未结 3 1922
南笙
南笙 2021-01-22 00:28

I have a block of code in a lock:

lock (obj)
{
  //...
}

I also have a property that locks on that same object. Simple enough scenario. My ques

相关标签:
3条回答
  • 2021-01-22 00:45

    My experience is that the VS.NET debugger does freeze from time to time, but it must have some deadlock detection and debug optimizations to avoid these types of issues.

    0 讨论(0)
  • 2021-01-22 01:01

    No the debugger will show you the properties of the object even if it is within a lock() block.

    Lock()ing the object does not actually prevent any access to the object - it simply creates a semaphore that will block any other code that attempts to lock the same object until the lock is released.

    0 讨论(0)
  • 2021-01-22 01:04

    Yes, the debugger executes watch expressions on a separate worker thread that's running inside the process. Which will hit the lock in your property getter and block. The debugger puts up with that for 5 seconds, then declares the watch expression unusable and displays "Function evaluation timed out".

    The debugger then gets grumpy, not much it can do with that blocked thread, you'll commonly see "Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation." Which is good advice.

    0 讨论(0)
提交回复
热议问题