Home All Groups Group Topic Archive Search About

Evaluating threads in an application

Author
9 Jun 2006 6:09 AM
Jerry Spence1
How can I gain access to all the threads running in my application? I'm
looking for something like:

Application.Threads.count
Application.threads(item).IsAlive
Application.threads(item).Name

etc.

-Jerry

Author
9 Jun 2006 8:35 AM
Larry Lard
Jerry Spence1 wrote:
> How can I gain access to all the threads running in my application?

First get a System.Diagnostics.Process by calling
System.Diagnostics.Process.GetCurrentProcess.

Then look in the ProcessThreadCollection returned from Process.Threads
- this is a collection of ProcessThread objects.

> I'm
> looking for something like:
>
>  Application.Threads.count

System.Diagnostics.Process.GetCurrentProcess.Threads.Count

> Application.threads(item).IsAlive

Interrogate the .ThreadState of each ProcessState. There's more to
thread state than alive or not alive...

> Application.threads(item).Name

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

--
Larry Lard
Replies to group please
Author
11 Jun 2006 6:39 AM
Jerry Spence1
Show quote Hide quote
"Larry Lard" <larryl***@hotmail.com> wrote in message
news:1149842101.593841.325780@h76g2000cwa.googlegroups.com...
>
> Jerry Spence1 wrote:
>> How can I gain access to all the threads running in my application?
>
> First get a System.Diagnostics.Process by calling
> System.Diagnostics.Process.GetCurrentProcess.
>
> Then look in the ProcessThreadCollection returned from Process.Threads
> - this is a collection of ProcessThread objects.
>
>> I'm
>> looking for something like:
>>
>>  Application.Threads.count
>
> System.Diagnostics.Process.GetCurrentProcess.Threads.Count
>
>> Application.threads(item).IsAlive
>
> Interrogate the .ThreadState of each ProcessState. There's more to
> thread state than alive or not alive...
>
>> Application.threads(item).Name
>
> Threads don't have names, they have a .Id of type Integer.
>
> --
> Larry Lard
> Replies to group please
>

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.Diagnostics.Process.GetCurrentProcess.Threads.Count it returns about
23 so there is more going on than I am interested in.

-Jerry
Author
12 Jun 2006 9:23 AM
Larry Lard
Jerry Spence1 wrote:
Show quoteHide quote
> "Larry Lard" <larryl***@hotmail.com> wrote in message
> news:1149842101.593841.325780@h76g2000cwa.googlegroups.com...
> >
> > Jerry Spence1 wrote:
> >> How can I gain access to all the threads running in my application?
> >
> > First get a System.Diagnostics.Process by calling
> > System.Diagnostics.Process.GetCurrentProcess.
> >
> > Then look in the ProcessThreadCollection returned from Process.Threads
> > - this is a collection of ProcessThread objects.
> >
> >> I'm
> >> looking for something like:
> >>
> >>  Application.Threads.count
> >
> > System.Diagnostics.Process.GetCurrentProcess.Threads.Count
> >
> >> Application.threads(item).IsAlive
> >
> > Interrogate the .ThreadState of each ProcessState. There's more to
> > thread state than alive or not alive...
> >
> >> Application.threads(item).Name
> >
> > Threads don't have names, they have a .Id of type Integer.
> >
>
> 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.Diagnostics.Process.GetCurrentProcess.Threads.Count it returns about
> 23 so there is more going on than I am interested in.

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