我目前正在尝试查看我在 C# 应用程序中创建的线程发生了什么。该线程的类型为 System.Threading.Thread
并嵌入内部对象内(并且我可以在调试时访问该对象内的线程)。
我正在使用“Process Explorer ”检查应用程序。
Process Explorer 有一个“Threads”选项卡,其中包含“TID”、“CPU”、“Cycles Delta”、“Suspend Count”和“Start Address”列。
为了识别我已经启动的线程(在调试器中),我相信我可以查找TID(线程ID)或起始地址,我认为线程ID是最清楚的。
但是,乍一看,我在 System.Threading.Thread
中没有看到任何属性/字段/属性。看起来像线程 ID 的类。
有人知道 System.Threading.Thread
的哪个属性/属性/字段吗?与 Process Explorer 的 TID 列相对应吗?
编辑:似乎有一个ManagedThreadId
但事实并非如此。
最佳答案
本质上,托管线程不是 native 线程,在任务管理器中寻找相关性是不合适的。欲了解更多信息,请参阅CLR Threading Overview - Managed vs. Native Threads
Managed code executes on "managed threads," which are distinct from the native threads provided by the operating system. A native thread is a thread of execution of native code on a physical machine; a managed thread is a virtual thread of execution on the CLR's virtual machine.
...
但是,如果您使用 Visual Studio,则可以使用线程窗口来调试托管线程。
View threads in the Visual Studio debugger by using the Threads window (C#, Visual Basic, C++)
Several Visual Studio user interface elements help you debug multithreaded apps. This article introduces multithreaded debugging features in the code editor window, Debug Location toolbar, and Threads window
Walkthrough: Debug a multithreaded app using the Threads window (C#, Visual Basic, C++
Visual Studio provides several tools and user interface elements to help you debug multithreaded applications. This tutorial shows how to use thread markers, the Parallel Stacks window, the Parallel Watch window, conditional breakpoints, and filter breakpoints. Completing this tutorial will familiarize you with Visual Studio features for debugging multithreaded applications.
关于c# - 与 Process Explorer 的 TID 相对应的 System.Threading.Thread 的属性/属性/字段是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69553009/