可能重复:
C#/.NET: How to get the thread id from a thread?获取线程ID
我怎样才能得到相同的线程ID,我看到它在Visual Studio?
我试图使用Thread.CurrentThread.ManagedThreadId
,但我得到不同的数字。
我得到35,38,39,等等,但在Visual Studio中我有10596,893,等...
可能重复:
C#/.NET: How to get the thread id from a thread?获取线程ID
我怎样才能得到相同的线程ID,我看到它在Visual Studio?
我试图使用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);
看一看堆栈溢出问题Getting the thread ID from a thread。
可以使用WINAPI功能GetCurrentThreadId和GetThreadId
如果您看到在您的实时应用程序中使用不同的线程ID,而不是在Visual Studio中进行调试时,这正是您应该看到的,对吗?
在调试器中运行时,您将有效地在调试器主机上运行应用程序,该应用程序的线程不会仅仅运行该应用程序。
'System.AppDomain.GetCurrentThreadId()'已过时/不建议使用。 – testing
已过时,但如果您尝试映射到您在Visual Studio的“线程”下拉菜单中看到的内容,那么它仍然是最佳选择 –