码迷,mamicode.com
首页 > 编程语言 > 详细

线程、线程ID获取

时间:2018-12-11 16:00:37      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:tar   size   通过   get   post   url   tle   thread   htm   

 

一、进程ID获取

1.1  当前进程的Id

方法1 通过进程名获取

Process[] processes = Process.GetProcesses(); 
foreach(Process process in processes) 
{ 
  if(process.ProcessName == "进程名" 
  { 
    MessageBox.Show(process.Id); 
  } 
}

方法2 直接获取

Process processes = Process.GetCurrentProcess
processes.id // 获得当前进程的ID

 

 

 

二、线程ID获取

2.1 C#获取当前线程ID

方法1 推荐

Thread.CurrentThread.ManagedThreadId

方法2

AppDomain.GetCurrentThreadId()

 

 

 

 

 

参考文章

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

由进程名获取进程ID及其主线程IDyanglx2022

 

 

线程、线程ID获取

标签:tar   size   通过   get   post   url   tle   thread   htm   

原文地址:https://www.cnblogs.com/arxive/p/10102175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!