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

how to get managed .net threads status

P: n/a
Hi -

I am writing a service which will check a process and its threads for
their state ( alive or dead ).

The process has 5 .net managed threads created using thread.start and
each have been assigned a name.

As in .net there is no way we can get the managed threads, I am
thinking of making a win32 call and check their status.

I need help with regards to which win32 api functions will help me to
get a list of threads ( not OS threads but the .net managed threads )
and to check their status ( thread.IsAlive ,something like that ).

How do i accomplish this. ?

If there is another way I can get the process and get its threads to
check their status,rather than going win32 it will be helpful.

thanks
BG

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

<by******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi -

I am writing a service which will check a process and its threads for
their state ( alive or dead ).

The process has 5 .net managed threads created using thread.start and
each have been assigned a name.

As in .net there is no way we can get the managed threads, I am
thinking of making a win32 call and check their status.


Sure there is a way to get the managed threads state...
ProcessThread.ThreadState Property
Willy.
Nov 17 '05 #2

P: n/a
Hi -

ProcessThread collection gives me all the threads associated with the
process ( meaning all the OS threads as well ).

I have created 5 threads in my service using Thread.Start and also given a
name Thread.Name = "x".

when I do

Process [] proc = Process.GetProcessByName("MyProcess");

foreach ( ProcessThread thread in proc[0].Threads )

I get 30 threads that are executing. The thread state doesn't have IsAlive
property which System.Threading.Thread has.

System.Diagnostics.ProcessThread and System.Threading.Thread are no way
related.

I hope you understand my question. I want to check whther my main threads
that I created for that process are alive or not. ( not the OS threads that
may or may not include my threads).

Also ProcessThread.Thread has Id property which System.Threading.Thread
doesn't. Pluse the Ids keep changing.
--
Bhavin Gandhi
Software Developer
Rockwell Automation
USA
"Willy Denoyette [MVP]" wrote:

<by******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi -

I am writing a service which will check a process and its threads for
their state ( alive or dead ).

The process has 5 .net managed threads created using thread.start and
each have been assigned a name.

As in .net there is no way we can get the managed threads, I am
thinking of making a win32 call and check their status.


Sure there is a way to get the managed threads state...
ProcessThread.ThreadState Property
Willy.

Nov 17 '05 #3

P: n/a
Oh, but you asked about the Win32 api's to get the thread status, right?
Managed threads aren't known by the OS so there are no Win32 API's to get
the 'status' of a managed threads.
All managed threads are associated with an OS thread, but if you are only
interested in the IsAlive property of a few of your threads you will have to
store the reference to the thread object in an array (or an hashtable keyed
with the thread name for easy lookup).
From this array you can select a thread to query its IsAlive property.

Willy.
Just wonder who created the other 25 threads in your process.

"BGandhi" <BG*****@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
Hi -

ProcessThread collection gives me all the threads associated with the
process ( meaning all the OS threads as well ).

I have created 5 threads in my service using Thread.Start and also given a
name Thread.Name = "x".

when I do

Process [] proc = Process.GetProcessByName("MyProcess");

foreach ( ProcessThread thread in proc[0].Threads )

I get 30 threads that are executing. The thread state doesn't have IsAlive
property which System.Threading.Thread has.

System.Diagnostics.ProcessThread and System.Threading.Thread are no way
related.

I hope you understand my question. I want to check whther my main threads
that I created for that process are alive or not. ( not the OS threads
that
may or may not include my threads).

Also ProcessThread.Thread has Id property which System.Threading.Thread
doesn't. Pluse the Ids keep changing.
--
Bhavin Gandhi
Software Developer
Rockwell Automation
USA
"Willy Denoyette [MVP]" wrote:

<by******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
> Hi -
>
> I am writing a service which will check a process and its threads for
> their state ( alive or dead ).
>
> The process has 5 .net managed threads created using thread.start and
> each have been assigned a name.
>
> As in .net there is no way we can get the managed threads, I am
> thinking of making a win32 call and check their status.
>


Sure there is a way to get the managed threads state...
ProcessThread.ThreadState Property
Willy.

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.