<分区>
Possible Duplicate:
C#/.NET: How to get the thread id from a thread?
如何获得与我在 Visual Studio 中看到的线程 ID 相同的线程 ID?
我已尝试使用 Thread.CurrentThread.ManagedThreadId
,但我得到的数字不同。
我得到 35、38、39 等,但在 Visual Studio 中我有 10596、893 等...
<分区>
Possible Duplicate:
C#/.NET: How to get the thread id from a thread?
如何获得与我在 Visual Studio 中看到的线程 ID 相同的线程 ID?
我已尝试使用 Thread.CurrentThread.ManagedThreadId
,但我得到的数字不同。
我得到 35、38、39 等,但在 Visual Studio 中我有 10596、893 等...
最佳答案
使用 GetCurrentThreadId() 或 ManagedThreadId() 获取线程 ID:
int threadID = (int)AppDomain.GetCurrentThreadId();
int managedThreadId = Thread.CurrentThread.ManagedThreadId;
Console.WriteLine("ThreadId = " + threadID);
Console.WriteLine("ManagedThreadId = " + managedThreadId);
看看 Stack Overflow 问题 Getting the thread ID from a thread .
关于c# - 获取线程 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6451615/