[英].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#. 我正在尝试监视用C#编写的Microsoft.NET应用程序中的一组线程的状态。 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. 在Java中,您可以将线程分配给线程组,并且它们的子项也将属于该组。 Is there an equivalent in .NET?
在.NET中有相同的东西吗?
I briefly looked at ExecutionContext and LogicalCallContext, but I can't see how to find all the threads that are in a context. 我简要地看了一下ExecutionContext和LogicalCallContext,但我看不到如何查找上下文中的所有线程。 Raymond Chen has an article about a Win32 API method for enumerating threads, but I hope I don't have to go that low.
Raymond Chen有一篇关于枚举线程的Win32 API方法的文章,但我希望我没有那么低。
You can enumerate the threads in your process using the Threads property of System.Diagnostics.Process. 您可以使用System.Diagnostics.Process的Threads属性枚举进程中的线程 。
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). 但请注意,您在此处获得的对象与您自己创建的对象类型不同(即不是System.Threading.Thread对象)。
A concept of thread groups does not exist however, AFAIK. 但是,AFAIK不存在线程组的概念。
他们正在“Task”API中进行类似的工作,这是Parallel Extensions的一部分。
Make it simple: 简单说明:
Create your ThreadGroup class with a method wrapping the thread creation process. 使用包装线程创建过程的方法创建ThreadGroup类。
When this method is called, it adds the created thread to a Collection and there is your group. 调用此方法时,它会将创建的线程添加到Collection中,并且存在您的组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.