如何在 Visual Studio 中调试单个线程? [英] How to debug a single thread in Visual Studio?

查看:77
本文介绍了如何在 Visual Studio 中调试单个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a solution with some projects. There are several break-points in different projects. I want to trace the first thread hit one of these break-points and continue tracing that single thread despite of other threads entering the same code-blocks.

我知道这可以通过在断点上定义条件来实现,即线程名称 = ... 或线程 Id = ... 但我的情况是负载很重的 ASP.NET 应用程序,一旦我附加到 w3wp.exe,许多线程就会中断-点.我需要一些类似 ThreadLocal 的东西.

I know this is possible through defining a condition on the break-point, that is, thread name = ... or thread Id = ... but my case is a heavy loaded ASP.NET application and as soon as I attach to w3wp.exe many threads will hit the break-points. I need some thing like a ThreadLocal<break-point>.

有可能吗?如果是,怎么办?

Is it possible? If so, how?

推荐答案

冻结/解冻线程是一种不正确的方式,因为其他线程不执行任何代码.

Freeze/Thaw threads is an incorrect way because other threads don't execute any code.

最正确和最有用的方法是:

The most correct and usable way is to:

  1. 在断点窗口中按 Ctrl+A(选择所有断点).
  2. 右键单击并选择过滤器...".
  3. 输入ThreadId=(当前线程ID)".

Visual Studio 2015 和更新版本中,过程类似:

In Visual Studio 2015 and newer, the process is similar:

  1. 在断点窗口中按 Ctrl+A(选择所有断点).
  2. 右键单击并选择设置...".
  3. 选中条件"并在下拉列表中选择过滤器"
  4. 输入ThreadId=(当前线程ID)".

所以所有线程都被执行,但调试器只命中当前线程.

So all threads are executed, but the debugger hits on the current thread only.

这篇关于如何在 Visual Studio 中调试单个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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