简体   繁体   中英

.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.

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 (ie are not System.Threading.Thread objects).

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

他们正在“Task”API中进行类似的工作,这是Parallel Extensions的一部分。

Make it simple:

Create your ThreadGroup class with a method wrapping the thread creation process.

When this method is called, it adds the created thread to a Collection and there is your group.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM