Grokking Active Threads

  • Thread starter Thread starter Bryan Murphy
  • Start date Start date
B

Bryan Murphy

I'm currently working on a page for our ASP.Net application that
displays some information about the runtime for the current machine.
The ultimate goal is to be able to determine what threads are running,
why they are running (i.e. where and when they got started), what
state they are in, and if there are any orphaned or dead threads that
should have been closed but weren't.

My problem, is that I have no idea how to get the "name" of a thread.
I can use Thread.CurrentThread.Name to get the name of the current
thread, but I can't get the name of any other threads using the
System.Diagnostics.Process.GetCurrentProcess().Threads
(ProcessThreadCollection) collection.

Is there a way for me to get the "name" of a thread using only it's
Thread ID? Also, is there a way to determine which thread created
which thread (that would be great, but I could fake it using the
Thread.Name property).

Bryan
 
Bryan,

The Name property is something that is exclusive to CLR threads (or
rather, the .NET representation of threads). Threads that are doled out by
the OS do not have names associated with them. In order to get the name of
a Thread object, you would have to attach to the running instance of the CLR
for that process, and then find the Thread objects and query the Name
property.

I don't even think something like this is even possible, and if it is,
it is bound to be very, very ugly.

If it was up to me, I would drop it, because you can't guarantee that a
name will always be there. Not all threads run in the context of the
runtime, so when you come across a thread that doesn't (and there will be
plenty if you are doing this machine-wide), you will not have that
information anyways.

Also, the threads don't really expose which thread created it, so you
can't get at that information either.

Hope this helps.
 
Back
Top