Search code examples
c#multithreadingprocess-explorer

What's the attribute/property/field of a System.Threading.Thread which corresponds with Process Explorer's TID?


I'm currently trying to see what's happening with a thread, I've created in a C# application. The thread is of type System.Threading.Thread and is embedded inside an internal object (and I have access to the thread inside that object while debugging).

I'm checking the application, using "Process Explorer".
Process Explorer has a "Threads" tab with columns "TID", "CPU", "Cycles Delta", "Suspend Count" and "Start Address".
In order to identify the thread I've started (in the debugger), I believe I can look for either the TID (Thread ID) or the start address, where I believe the thread ID to be the clearest.

However, at first sight I don't see any property/field/attribute in the System.Threading.Thread class which looks like a thread ID.

Does anybody know which attribute/property/field of System.Threading.Thread corresponds with Process Explorer's TID column?

Edit: there seems to be a ManagedThreadId but that's not it.


Solution

  • Essentially, Managed Threads are not Native Threads, looking for a correlation in Task Manager will not be suitable. For more information see 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.

    ...

    However, if you are using Visual studio you can use the Thread Window to debug managed threads.

    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.