Is it possible to enumerate all managed threads in C#? Visual Studio seems to be able to do this when you hit a break point while debugging. In the "Threads" window it shows a list of all running threads, including managed names. Does anyone know how it does this?
是否可以枚举C#中的所有托管线程?当您在调试时遇到断点时,Visual Studio似乎能够执行此操作。在“线程”窗口中,它显示所有正在运行的线程的列表,包括托管名称。有谁知道这是怎么回事?
3 个解决方案
#1
Debuggers are often able to do things "normal" code can't. You'd probably find that you can do this if you use the profiling/debugging API, but I don't believe you can do it from "normal" .NET code.
调试器往往能够做“正常”代码不能做的事情。如果使用分析/调试API,您可能会发现可以执行此操作,但我不相信您可以从“普通”.NET代码中执行此操作。
#2
This sounds like a duplicate of "How to enumerate threads in .NET using the Name property?" - If so, the short answer is "keep track of your own threads yourself" - i.e. in a List<Thread>
or similar.
这听起来像是“如何使用Name属性在.NET中枚举线程?”的副本。 - 如果是这样,简短的回答是“自己跟踪自己的线程” - 即在List
#3
Take a look at Managed Stack Explorer:
看一下Managed Stack Explorer:
MSE works by quickly attaching to a process when a stack trace is requested and the detaching the second the stack trace has been retrieved. This way the interference in the normal operation of the process is minimized.
MSE通过在请求堆栈跟踪时快速附加到进程并且在第二个分离堆栈跟踪已被检索的情况下工作。这样,最小化了过程正常操作中的干扰。
Unfortunately, this means it has to done by an external process.
不幸的是,这意味着必须通过外部流程完成。
A similar tool is StackDump, which uses MDbg to generate the dump.
类似的工具是StackDump,它使用MDbg生成转储。
#1
Debuggers are often able to do things "normal" code can't. You'd probably find that you can do this if you use the profiling/debugging API, but I don't believe you can do it from "normal" .NET code.
调试器往往能够做“正常”代码不能做的事情。如果使用分析/调试API,您可能会发现可以执行此操作,但我不相信您可以从“普通”.NET代码中执行此操作。
#2
This sounds like a duplicate of "How to enumerate threads in .NET using the Name property?" - If so, the short answer is "keep track of your own threads yourself" - i.e. in a List<Thread>
or similar.
这听起来像是“如何使用Name属性在.NET中枚举线程?”的副本。 - 如果是这样,简短的回答是“自己跟踪自己的线程” - 即在List
#3
Take a look at Managed Stack Explorer:
看一下Managed Stack Explorer:
MSE works by quickly attaching to a process when a stack trace is requested and the detaching the second the stack trace has been retrieved. This way the interference in the normal operation of the process is minimized.
MSE通过在请求堆栈跟踪时快速附加到进程并且在第二个分离堆栈跟踪已被检索的情况下工作。这样,最小化了过程正常操作中的干扰。
Unfortunately, this means it has to done by an external process.
不幸的是,这意味着必须通过外部流程完成。
A similar tool is StackDump, which uses MDbg to generate the dump.
类似的工具是StackDump,它使用MDbg生成转储。