Is there a way to get a Thread's ThreadName from a ThreadId? (from say, a ThreadID like 10, or 15, etc.)
+8
A:
Not in managed code. You can't even get a list of Thread
objects for the current process, as far as I'm aware. You can get the ProcessThread
s with Process.Threads
and ProcessThread
provides an Id
property, if that helps you... but a ProcessThread
doesn't have a name as far as I can tell :(
Jon Skeet
2009-04-14 17:11:45
Oh.. That's quite a pity then cause the System.Diagnostics.TraceListener class has methods that allows you to get a Thread ID via TraceEventCache.ThreadId, except that a number is not very meaningful as it doesn't say alot.. and varies from run to run too! :(
littleduckie
2009-04-14 17:16:10
Are these your own threads? If so, when you create the thread you could log the name and ID, and match them up later.
Jon Skeet
2009-04-14 17:26:28
+1
A:
The best information that I could find is here:
http://www.mail-archive.com/[email protected]/msg07369.html
That doesn't seem too helpful, though. It seems that there is no good way to do this, short of you changing the code to maintain a list (or dictionary) of all of your application's threads.
jsight
2009-04-14 17:21:41