c# - 获取线程 ID

标签 c# .net visual-studio multithreading

<分区>

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/

相关文章:

.net - 是否可以在 VC++/CLI 中重写 IEnumerable?

windows - 在 Visual Studio 中签署 C++ 可执行文件

c# - MVC无参数

c# - 任何人翻译 X12 271 医疗响应

.net - VB.Net Lambda 查询

c# - 将属性添加到列表?

c++ - Visual Studios 9 不一致的 Dll 链接

c# - Visual Studio 2017 中的 Pythonnet

c# - 子报表 RDLC 数据检索失败

c# - 确保方法逻辑在没有 bool 标志的情况下执行一次的更好方法