运行程序后,我想知道本进程的ID,如何得到?

解决方案 »

  1.   


    Process[]   proe   =   Process.GetProcesses(); 
                            foreach   (Process   proc   in   proe) 
                            { 
                                    foreach   (ProcessThread   var   in   proc.Threads) 
                                    { 
                                            listBox1.Items.Add(proc.ProcessName+ "             "+var.Id); 
                                    } 
                            } 
      

  2.   

    如果是本程序中获取。Process str = Process.GetCurrentProcess();
                this.textBox3.Text = str.ProcessName;
                this.textBox2.Text = str.Id.ToString();//进程id
    如果是别的程序中获取,那么值可以根据进程名称获取,如果有多个,就得看有什么调节进行筛选。process有很多属性,你自己看看,根据他们进行筛选。
      

  3.   


    System.Diagnostics.Process p= System.Diagnostics.Process.GetCurrentProcess();
    int id= p.Id;
    //这样不可以吗?
      

  4.   

    GetCurrentProcessID 这个直接就是得到当前