c# 怎样获得想要的线程ID

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:40:22
不是当前的
大侠们能指出相应的参数吗 在下感激不尽

GetThreadId 根据线程句柄得到线程ID。

GetWindowThreadProcessId ,根据窗口句柄得到此窗口所在线程的ID(也同时得到进程的ID)

OpenThread,能根据ID得到线程的句柄

这个问题给100分。。。你很大方啊。
GetThreadId 根据线程句柄得到线程ID。

GetWindowThreadProcessId ,根据窗口句柄得到此窗口所在线程的ID(也同时得到进程的ID)

OpenThread,能根据ID得到线程的句柄

获取在关联进程中运行的一组线程:Process.Threads 属性
获取线程的唯一标识符:ProcessThread.Id

必须借助于系统---下面是windows操作系统---例如你要将启动的一个Excel进程中的某个线程获取到,并且关闭,要求此时不影响其他使用。可以操作如下:
[System.Runtime.InteropServices.DllImport("User32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
private void Kill(Microsoft.Office.Interop.Excel.Application excel)
{
IntPtr t = new IntPtr(excel.Hwnd); //得到这个句柄,具体作用是得到这块内存入口

int k = 0;
GetWindowThreadProcessId(t, out k); //得到唯一标志k
System.Diagnostics.Proce