C#Visual Studio调试器UI行为与锁 [英] C# Visual Studio Debugger UI behavior with lock

查看:118
本文介绍了C#Visual Studio调试器UI行为与锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在锁中有一个代码块:

I have a block of code in a lock:

lock (obj)
{
  //...
}

我还有一个锁定在同一个对象上的属性。简单的场景我的问题是,如果我在我锁定的代码块中放置一个断点,然后检查Visual Studio调试器中的属性,会发生什么?调试器会死机,直到我断点(或杀死visual studio / debug)后继续执行?或者调试器根本不会显示属性的数据(从UI中获取后台线程中的数据)

I also have a property that locks on that same object. Simple enough scenario. My question is, if I put a breakpoint inside my locked block of code, and then examine the property in the Visual Studio debugger, what will happen? Will the debugger deadlock until I continue executing after breakpoint (or kill visual studio/debugging)? Or will the debugger simply not show any data for the property (grabbing data in background thread from UI?)

我问的原因是我有一个属性(并且仅用于调试目的;我很好,偶尔在这种情况发生时不会显示数据,但是在调试器(和可视化工作室)中遇到了很多不好的调试器属性的时候,我宁愿避免在某些时候阻止我的调试工作的代码我试图帮助开始!

The reason I ask is I've got a property specifically (and only) for debugging purposes; I'm OK with it occasionally not showing data when this scenario happens, but having crashed the debugger (and visual studio) many a time with bad debugger attributes, I'd rather avoid code that could at some point hamper my debugging efforts when that's what I'm trying to aid to begin with!

我计划在某些时候测试一下,当我有更多的时间,但希望能够更快的答案可以知道更好的人。

I plan on testing this at some point when I've got some more time, but was hoping for a quicker answer from someone who might know better.

推荐答案

是的,调试器在进程内部运行的单独的工作线程上执行watch表达式。这将触发您的属性getter和block中的锁定。调试器放置5秒钟,然后声明手表表达式不可用,并显示功能评估超时。

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.

这篇关于C#Visual Studio调试器UI行为与锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆