Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET equivalent to Java thread groups?

I'm trying to monitor the states of a group of threads in a Microsoft.NET application written in C#. I'd like to be able to also monitor any child threads spawned by the original threads.

In Java, you can assign threads to a thread group, and their children will also belong to the group. Is there an equivalent in .NET?

I briefly looked at ExecutionContext and LogicalCallContext, but I can't see how to find all the threads that are in a context. Raymond Chen has an article about a Win32 API method for enumerating threads, but I hope I don't have to go that low.


2 Answers

You can enumerate the threads in your process using the Threads property of System.Diagnostics.Process.

Note however, that the objects you get here are not of the same type as those you create to start threads yourself (i.e. are not System.Threading.Thread objects).

A concept of thread groups does not exist however, AFAIK.

like image 194
Christian.K Avatar answered Aug 08 '26 10:08

Christian.K


They are working on something like that in their "Task" API, which is part of Parallel Extensions.

like image 29
Jonathan Allen Avatar answered Aug 08 '26 11:08

Jonathan Allen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!