473,388 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

how to get managed .net threads status

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
3 22137

<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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WinstonSmith | last post by:
Hallo everyone, is there a way to get a list of all threads an application written in C# uses? Thanks in advance Matthias
5
by: John Wood | last post by:
Does anyone know how to enumerate the managed threads in the current process? Process.Threads gives you a list of ProcessThreads, but I want to somehow get a list of the managed threads... --...
15
by: _BNC | last post by:
Recently I had posted a query about intermittent problems with a C++/Interop scheme (unmanaged C DLL wrapped in unmanaged C++, wrapped in managed C++, all accessed by C#). The system works fine...
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
2
by: R. Nachtsturm | last post by:
Hi, i have the problem that when i create a low priority background thread, start it, and wait for it to finish that it does not seem to terminate even after it is finished.. if i use...
1
by: Jon | last post by:
My question is: Can the Garbage Collector (GC) suspended a managed thread while it is executing native code. The reason I am interested in this is that I have: 1) a native thread (N) that only...
6
by: Gunga Din | last post by:
I must be missing it somehow... I need to count the number of threads running, not just those started by my application. Rather like the Task Manager, I would like to get the total number of...
3
by: tshad | last post by:
I need to find out how many threads a process has. I have used ThreadPool.GetAvailableThreads and ThreadPool.GetMaxThreads, but they both show 50 for worker threads and 100 for port threads. ...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.