From my current process in .NET I can get a list of all its threads. Is it possible to find out what kind of thread it is? To get details if it's for example a worker, IO, CLR, backgroud or main thread?
A:
There is not going to be a one-size-fits-all solution for doing this.
- You can check the
Thread.IsBackground
property to see if it is a background thread (that is according to the definition of background that the property is using that is). - You can take advantage of the
Thread.Name
name property to identify it later. - You can use thread local storage to stuff information "into" a thread which you can extract later to identify it.
- You can use the
Thread.IsThreadPoolThread
to see if it is a thread managed by the thread pool.
Each of these has their own advantages and disadvantages. I think you are going to find it difficult to identify a thread without having attached some kind of information to it ahead of time.
Brian Gideon
2010-07-28 21:02:16