I am trying to print info about all threads running in a given program/process, by using the code below. For a console program (VS2015, NET 4.6, Windows 10), I am getting five threads. The problem is that that class ProcessThread does not include many thread properties like about background, name, etc. The class Thread has more info but it is available only from the current thread and not from another thread, even of the same process. At the minimum I want to get info like IsBackground, and name/desc about the function of the thread.
ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads;
int count = 0;
Console.WriteLine("ManagedThreadId: {0}", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("GetCurrentThreadId: {0}", AppDomain.GetCurrentThreadId());
Console.WriteLine("Process name: {0}", Process.GetCurrentProcess().ProcessName);
Console.WriteLine("Process threads: {0}", currentThreads.Count);
foreach (ProcessThread thread in currentThreads)
{
Console.WriteLine(" Thread {0}:", ++count);
Console.WriteLine(" Name: {0}", thread.ToString()); // meaningless
Console.WriteLine(" GetType: {0}", thread.GetType()); // meaningless
Console.WriteLine(" Id: {0}", thread.Id);
Console.WriteLine(" State: {0}", thread.ThreadState);
if (thread.ThreadState == System.Diagnostics.ThreadState.Wait)
Console.WriteLine(" WaitReason: {0}", thread.WaitReason);
Console.WriteLine(" PriorityLevel: {0}", thread.PriorityLevel);
Console.WriteLine(" BasePriority: {0}", thread.BasePriority);
Console.WriteLine(" CurrentPriority: {0}", thread.CurrentPriority);
}