gpt4 book ai didi

c# - 如何从 Process.GetCurrentProcess().Threads 获取托管线程

转载 作者:太空宇宙 更新时间:2023-11-03 18:50:46 27 4
gpt4 key购买 nike

我可以从 Process.GetCurrentProcess().Threads 获取正在运行的线程列表,但我需要知道以 Thread.Start 开始的线程的托管名称。但它不是 ProcessThread 对象的属性。有没有办法从 ProcessThread 获取此信息?

最佳答案

虽然 CLR 为每个托管线程生成一个 OS 线程,但这并不是强制的。我的意思是,没有标准保证操作系统线程和托管线程之间应该存在一对一的映射。

引用MSDN:

An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host can use the CLR Hosting API to schedule many managed threads against the same operating system thread, or to move a managed thread between different operating system threads.

关于c# - 如何从 Process.GetCurrentProcess().Threads 获取托管线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/466632/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com