Jon Tackabury
Jon Tackabury

Reputation: 49247

How can I get managed threads from Process.GetCurrentProcess().Threads

I can get a list of running threads from Process.GetCurrentProcess().Threads, but I need to know the managed name of threads started with Thread.Start. It isn't a property on the ProcessThread object though. Is there a way to get this information from a ProcessThread?

Upvotes: 1

Views: 2824

Answers (1)

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422016

While CLR spawns an OS thread for each managed thread, it's not forced to. I mean, no standard guarantees that there should be a one to one mapping between OS threads and managed threads.

To quote 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.

Upvotes: 7

Related Questions