Evaluating threads in an application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry Spence1

    #1

    Evaluating threads in an application

    How can I gain access to all the threads running in my application? I'm
    looking for something like:

    Application.Thr eads.count
    Application.thr eads(item).IsAl ive
    Application.thr eads(item).Name

    etc.

    -Jerry


  • Larry Lard

    #2
    Re: Evaluating threads in an application


    Jerry Spence1 wrote:[color=blue]
    > How can I gain access to all the threads running in my application?[/color]

    First get a System.Diagnost ics.Process by calling
    System.Diagnost ics.Process.Get CurrentProcess.

    Then look in the ProcessThreadCo llection returned from Process.Threads
    - this is a collection of ProcessThread objects.
    [color=blue]
    > I'm
    > looking for something like:
    >
    > Application.Thr eads.count[/color]

    System.Diagnost ics.Process.Get CurrentProcess. Threads.Count
    [color=blue]
    > Application.thr eads(item).IsAl ive[/color]

    Interrogate the .ThreadState of each ProcessState. There's more to
    thread state than alive or not alive...
    [color=blue]
    > Application.thr eads(item).Name[/color]

    Threads don't have names, they have a .Id of type Integer.

    --
    Larry Lard
    Replies to group please

    Comment

    • Jerry Spence1

      #3
      Re: Evaluating threads in an application


      "Larry Lard" <larrylard@hotm ail.com> wrote in message
      news:1149842101 .593841.325780@ h76g2000cwa.goo glegroups.com.. .[color=blue]
      >
      > Jerry Spence1 wrote:[color=green]
      >> How can I gain access to all the threads running in my application?[/color]
      >
      > First get a System.Diagnost ics.Process by calling
      > System.Diagnost ics.Process.Get CurrentProcess.
      >
      > Then look in the ProcessThreadCo llection returned from Process.Threads
      > - this is a collection of ProcessThread objects.
      >[color=green]
      >> I'm
      >> looking for something like:
      >>
      >> Application.Thr eads.count[/color]
      >
      > System.Diagnost ics.Process.Get CurrentProcess. Threads.Count
      >[color=green]
      >> Application.thr eads(item).IsAl ive[/color]
      >
      > Interrogate the .ThreadState of each ProcessState. There's more to
      > thread state than alive or not alive...
      >[color=green]
      >> Application.thr eads(item).Name[/color]
      >
      > Threads don't have names, they have a .Id of type Integer.
      >
      > --
      > Larry Lard
      > Replies to group please
      >[/color]

      Thanks Larry

      Not being able to get at the thread names is a problem. I am trying to
      monitor the state of the threads in my project. How can I identify each
      thread? I have created about 6 threads (and know their names) but when I do
      System.Diagnost ics.Process.Get CurrentProcess. Threads.Count it returns about
      23 so there is more going on than I am interested in.

      -Jerry


      Comment

      • Larry Lard

        #4
        Re: Evaluating threads in an application


        Jerry Spence1 wrote:[color=blue]
        > "Larry Lard" <larrylard@hotm ail.com> wrote in message
        > news:1149842101 .593841.325780@ h76g2000cwa.goo glegroups.com.. .[color=green]
        > >
        > > Jerry Spence1 wrote:[color=darkred]
        > >> How can I gain access to all the threads running in my application?[/color]
        > >
        > > First get a System.Diagnost ics.Process by calling
        > > System.Diagnost ics.Process.Get CurrentProcess.
        > >
        > > Then look in the ProcessThreadCo llection returned from Process.Threads
        > > - this is a collection of ProcessThread objects.
        > >[color=darkred]
        > >> I'm
        > >> looking for something like:
        > >>
        > >> Application.Thr eads.count[/color]
        > >
        > > System.Diagnost ics.Process.Get CurrentProcess. Threads.Count
        > >[color=darkred]
        > >> Application.thr eads(item).IsAl ive[/color]
        > >
        > > Interrogate the .ThreadState of each ProcessState. There's more to
        > > thread state than alive or not alive...
        > >[color=darkred]
        > >> Application.thr eads(item).Name[/color]
        > >
        > > Threads don't have names, they have a .Id of type Integer.
        > >[/color]
        >
        > Thanks Larry
        >
        > Not being able to get at the thread names is a problem. I am trying to
        > monitor the state of the threads in my project. How can I identify each
        > thread? I have created about 6 threads (and know their names) but when I do
        > System.Diagnost ics.Process.Get CurrentProcess. Threads.Count it returns about
        > 23 so there is more going on than I am interested in.[/color]

        Well I must admit I have never done this kind of stuff, and it seems I
        led you astray somewhat. It turns out there isn't necessarily aone to
        one relationship between Thread objects (the things we create and
        manipulate) and the actual OS level threads (as reported to us by
        Diagnostics), so this is the wrong approach.

        It looks like if you want to track your Thread objects properly, you
        have to do it yourself, with an app-wide collection (with thread-safe
        access, of course... possibly by wrapping it in something that mediates
        access)

        --
        Larry Lard
        Replies to group please

        Comment

        Working...