I have a java application which on execution runs different thread. I want to see if particular thread (By thread name) is running or not. I can check this manually using JConsole. It shows me whether that thread is running in associated process or not. By inspiring from that.
I am creating a C# program to get threads associated with particular process. I need to get name of threads in particular. I have tried toString method but it does not shows thread name.
Below is the code:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
try
{
Process localById = Process.GetProcessById(6440);
ProcessThreadCollection coll = localById.Threads;
foreach (ProcessThread t in coll)
{
Console.WriteLine(t.toString());
}
}
catch (Exception e) { }
}
}
Output is :
System.Diagnostics.ProcessThread
System.Diagnostics.ProcessThread
System.Diagnostics.ProcessThread
Can anyone help me with this? Need to get name of all threads running in process by process ID.