c# - .Net 应用程序中的 native 线程

标签 c# debugging

当我在 WinDbg 中发出 ~* e !clrstack 命令以识别控制台应用程序中线程的 clr 调用堆栈时,它列出了 5 个线程。其中 3 个是托管线程(主线程、我创建的线程、垃圾收集线程(我预计))。 2 个是 native 线程。我没有创建任何 native 线程。

这些本地线程做什么?我在哪里可以获得更多信息?

下面列出了 ~* e !clrstack 命令的输出

0:004> ~* e !clrstack
OS Thread Id: 0x1ab8 (0)
ESP       EIP     
0012f3c0 7c90e514 [HelperMethodFrame: 0012f3c0] System.Threading.Thread.SleepInternal(Int32)
0012f414 79299275 System.Threading.Thread.Sleep(Int32)
0012f418 00c602bf testlock.LockTest.Test()
0012f458 00c60131 testlock.Program.Main(System.String[])
0012f69c 79e71b4c [GCFrame: 0012f69c] 
OS Thread Id: 0x1008 (1)
Unable to walk the managed stack. The current thread is likely not a 
managed thread. You can run !threads to get a list of managed threads in
the process
OS Thread Id: 0x209c (2)
Failed to start stack walk: 80004005
OS Thread Id: 0x1490 (3)
ESP       EIP     
00d6f74c 7c90e514 [GCFrame: 00d6f74c] 
00d6f81c 7c90e514 [HelperMethodFrame_1OBJ: 00d6f81c] System.Threading.Monitor.Enter(System.Object)
00d6f874 00c602b3 testlock.LockTest.Test()
00d6f8b4 00c6022c testlock.Program+<>c__DisplayClass1.<Main>b__0()
00d6f8c0 792d6d66 System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
00d6f8cc 792e01ef System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
00d6f8e4 792d6ce4 System.Threading.ThreadHelper.ThreadStart()
00d6fb0c 79e71b4c [GCFrame: 00d6fb0c] 
OS Thread Id: 0x1cb8 (4)
Unable to walk the managed stack. The current thread is likely not a 
managed thread. You can run !threads to get a list of managed threads in
the process

最佳答案

当 Windows 运行您的应用程序时,它会设置几个非托管线程。这是完全正常的。

您可以通过各种命令从非托管线程获取堆栈跟踪,例如:

.kb100
!dumpstack

就我个人而言,我喜欢 !dumpstack 的输出,它为您提供了组合的托管和非托管堆栈。

如果您只想查看托管线程,请尝试

!threads

Tess Ferrandez 在 her blog 中描述了您在调试时会看到的一些正常问题。 :

http://blogs.msdn.com/b/tess/archive/2005/12/20/things-to-ignore-when-debugging-an-asp-net-hang.aspx

关于c# - .Net 应用程序中的 native 线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3547186/

相关文章:

angular - 通过 Visual Studio Community 2017 在 Firefox 中调试 Angular 7 应用程序

c# - 取消选择列表框值

c# - 当结果为空时,MySqlDataAdapter.Fill 返回什么?

c# - libvideo获取youtube视频可读流

java - 如何在 Java API 中进行代码调试 - 编程风格

debugging - 如何检测 IE8 是否在兼容性 View 中运行?

objective-c - 如何从 obj-c/ios 中的堆栈跟踪获取源代码行

java - 有没有一种简单的方法可以将日志记录从依赖项插入到类中?

c# - 返回 SqlConnection 或 MySqlConnection 的方法

c# - ClickOnce 部署错误 : different computed hash than specified in manifest