我有一些项目的解决方案。在不同的项目中有几个断点。我希望跟踪第一个到达这些断点之一的线程,并继续跟踪该单个线程,尽管其他线程进入相同的代码块。

我知道这是可能的,通过在断点上定义一个条件,即线程名称=…或者线程Id =…但我的案子是个沉重的ASPNET应用程序,一旦我附加到w3wp.exe许多线程将击中断点。我需要一些东西,比如ThreadLocal<断点>。

这可能吗?如果有,怎么做?


当前回答

我刚刚发布了一个Visual Studio 2010+扩展,它完全可以满足你的需求。 而且它是免费的:)。

Presentation This Visual Studio extension adds two shortcuts and toolbar buttons to allow developers to easily focus on single threads while debugging multi-threaded applications. It dramatically reduces the need to manually go into the Threads window to freeze/thaw all threads but the one that needs to be followed, and therefore helps improve productivity. Features Restrict further execution to the current thread only. Will freeze all other threads. Shortcut: CTRL+T+T or Snowflake button. Switch to the next single thread (based on ID). Will change current thread and freeze all other threads. Shortcut: CTRL+T+J or Next button.

在这里的画廊,在官方页面或Github仓库检查它。

其他回答

在VS2019中,条件断点为tid == xxxxx 这样,断点将只在该线程上被命中

在VS 2019中:

在某处设置断点。 点击F5(继续)直到你的线程出现。 单击断点以删除它。 您可以使用F10或F11进行线程步进。

我建议在活动服务器上添加应用程序的另一个实例,或者在相同的硬件上,或者在新的机器上(集群它),然后只调试该实例。我不会在用户触发的代码中添加断点。如果这不是一个选择,我将添加更多的跟踪。

然而,如果这是绝对必要的,并且您需要一个解决方案统计,我相信您可以添加一个断点,它只在请求来自您的IP地址时中断。您可以通过添加一个检查HttpContext.Request.UserHostAddress的条件断点来做到这一点。但是请注意,这会大大降低应用程序的速度。

我认为这在Visual Studio 2015中略有不同。他们已经改变了断点中的一些东西,但下面是如何应用hzdbyte(上面)接受的答案:

在编码边距的断点上,右键单击>条件>从“条件表达式”更改为“筛选器”。这允许你通过ThreadId进行过滤。

或者在断点窗口中的断点上,右键单击>设置>勾选条件框并执行上述操作。

我刚刚发布了一个Visual Studio 2010+扩展,它完全可以满足你的需求。 而且它是免费的:)。

Presentation This Visual Studio extension adds two shortcuts and toolbar buttons to allow developers to easily focus on single threads while debugging multi-threaded applications. It dramatically reduces the need to manually go into the Threads window to freeze/thaw all threads but the one that needs to be followed, and therefore helps improve productivity. Features Restrict further execution to the current thread only. Will freeze all other threads. Shortcut: CTRL+T+T or Snowflake button. Switch to the next single thread (based on ID). Will change current thread and freeze all other threads. Shortcut: CTRL+T+J or Next button.

在这里的画廊,在官方页面或Github仓库检查它。