Grokking Active Threads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bryan Murphy

    #1

    Grokking Active Threads

    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.CurrentT hread.Name to get the name of the current
    thread, but I can't get the name of any other threads using the
    System.Diagnost ics.Process.Get CurrentProcess( ).Threads
    (ProcessThreadC ollection) 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
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Grokking Active Threads

    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]
    - nicholas.paldin o@exisconsultin g.com

    "Bryan Murphy" <news@humaninte rests.com> wrote in message
    news:b1b1431c.0 307110752.7ee73 b8a@posting.goo gle.com...[color=blue]
    > 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.CurrentT hread.Name to get the name of the current
    > thread, but I can't get the name of any other threads using the
    > System.Diagnost ics.Process.Get CurrentProcess( ).Threads
    > (ProcessThreadC ollection) 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[/color]


    Comment

    Working...