我可以从 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.
我是一名优秀的程序员,十分优秀!