C# 获得当前 进程 或 线程的ID

如果获得当前进程的Id用:

Process[] processes = Process.GetProcesses(); 
foreach(Process process in processes) 

if(process.ProcessName == "进程名" 

MessageBox.Show(process.Id); 

}

Process processes   =Process.GetCurrentProcess

processes.id获得当前进程的ID

如果获得当前线程的ID用:

Thread.CurrentThread.ManagedThreadId.ToString() (推荐)

AppDomain.GetCurrentThreadId().ToString()

posted @ 2016-11-01 17:37  comsky  阅读(48542)  评论(0编辑  收藏  举报