By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,671 Members | 1,403 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,671 IT Pros & Developers. It's quick & easy.

Grokking Active Threads

P: n/a
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().Thr eads
(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
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Bryan Murphy" <ne**@humaninterests.com> wrote in message
news:b1**************************@posting.google.c om...
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().Thr eads
(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

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.