从一个线程获取线程ID [英] Getting the thread ID from a thread

查看:313
本文介绍了从一个线程获取线程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#例如调试线程时,你可以看到每个线程的ID。

In C# when debugging threads for example, you can see each thread's ID.

我无法找到一个办法让同一个线程编程。我甚至不能得到当前线程的ID(在属性中的 Thread.currentThread )。

I couldn't find a way to get that same thread, programmatically. I could not even get the ID of the current thread (in the properties of the Thread.currentThread).

所以,我不知道如何Visual Studio中获得线程的ID,是有办法获得线程与手柄ID 2345 ,例如?

So, I wonder how does Visual Studio get the IDs of the threads, and is there a way to get the handle of the thread with id 2345, for example?

推荐答案

GetThreadId 返回给定本地线程的ID。有办法让它与托管线程工作,我敢肯定,你需要找到的是线程句柄,并把它传递给这个函数。

GetThreadId returns the ID of a given native thread. There's ways to make it work with managed threads, I'm sure, all you need to find is the thread handle and pass it to that function.

GetCurrentThreadId 返回当前线程的ID。

GetCurrentThreadId returns the ID of the current thread.

有关.NET的最新版本,这样做的目前推荐的方式,它是<一个href="http://msdn.microsoft.com/en-us/library/system.threading.thread.managedthreadid.aspx"><$c$c>System.Threading.Thread.CurrentThread.ManagedThreadId.

For the latest version of .NET, the current recommended way of doing it is System.Threading.Thread.CurrentThread.ManagedThreadId.

这篇关于从一个线程获取线程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆