Getting from ProcessThread to a managed thread

こ雲淡風輕ζ 提交于 2019-11-29 02:06:55

This is impossible for the following reason. Quote from 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.

So there's no one-to-one mapping between managed threads and OS threads.

So now the question becomes, how to get a list of all the managed threads currently running in the current process? Unfortunately I don't know the answer.

Bigtoe

It does not look like this is possible.
Luckily for us we have our own threading libraries which wrap the .NET libraries and I was able to put in functionality to keep a list of active threads that we can use for these diagnostics.
This works quite well but there was a fair bit of effort involved and testing of course, but hopefully we'll get o the bottom of it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!