1

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.

default locale
  • 13,035
  • 13
  • 56
  • 62
  • 1
    Check out this more general question: http://stackoverflow.com/questions/9366722/how-to-get-the-name-of-a-win32-thread – default locale Jul 03 '13 at 12:40
  • Thanks that is helping. But if I use jconsole and connect with java application then I can get all thread with their names. so is it possible to see name of thread running in other program by a different program in java – Sachin Singh Jul 05 '13 at 17:30
  • Answer by the link in my previous comment shows that windows doesn't support thread name retrieval. So, there is probably no "pure .Net" way to do this and you should interact with Java VM to access thread names. Look into [JMX](http://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html). – default locale Jul 06 '13 at 18:51

0 Answers0