Process[] proe = Process.GetProcesses();
            foreach (Process proc in proe)
            {
                foreach (ProcessThread var in proc.Threads)
                {
                    listBox1.Items.Add(proc.ProcessName+"      "+var.Id);
                }
            }
我想得到进程里的主线程ID号,。NET里应该怎么取才能得到。谢谢。 

解决方案 »

  1.   

    http://www.tech-online.cn/info/8528.htm
      

  2.   

    hdt(倦怠) ( ) 信誉:120    Blog   加为好友  
    你那个是进程,而非线程
    ///////////////////////////////////////////////////
    我这个FOREACH不就是取进程的所有线程吗?我现在要想知道这个进程的主线程ID?
    foreach (ProcessThread var in proc.Threads)
                    {
                        listBox1.Items.Add(proc.ProcessName+"      "+var.Id);
                    }
      

  3.   

    [DllImport("user32.dll",CharSet=CharSet.Auto)]
    public static extern int GetWindowThreadProcessID(IntPtr hWnd, int lpdwProcessId);[DllImport("kernel32.dll", CharSet=Charset.Auto)]
    public static extern int GetCurrentThreadID();上面Win32API的方法, 两个选一个就行
      

  4.   

    using System.Threading;Thread.CurrentThread.Name + Thread.CurrentThread.ManagedThreadId.ToString();
      

  5.   

    GetWindowThreadProcessID这个函数,要提供窗口句柄,万一没窗口的呢杂办呢
      

  6.   

    GetWindowThreadProcessID这个函数是获得跟窗口关联的线程的ID, 没有窗口的话, 就用GetCurrentThreadID
      

  7.   

    GetCurrentThreadID只是取到当前线程的ID吧,我的问题是要想得到进程里的主线程ID。一个进程里有很多线程啊。我不知道哪个线程才是主线程。我是想得到主线程ID。
      

  8.   

    Search CodeProject 
    有现成的
      

  9.   

    没找到,其实我就是想知道有没有现成的API函数可以直接重知道的进程ID取这个进程的主线程ID。