As the Thread Studio window, Visual Studio identifies the "main theme",

Most likely, I missed something obvious, but the humor of me ...

I always like to name important threads in my applications, as it is useful when debugging / registering etc. If you request the name of the main thread through Thread.CurrentThread.Name when the program starts, you will return null . That way, I always guarantee that the first thing that happens is that the main thread (and any other related threads) is given a beautiful meaningful name for the future link.

I never thought about this until today, but when viewing the Threads window in Visual Studio (before assigning thread names, etc.), a special category is assigned to the "Main thread", as well as the name of the pseudo, which also reads "Main thread" ( but this is not the name of the actual thread).

From a management point of view, .NET does not reveal anything meaningful either on System.Threading.Thread or on System.Diagnostics.ProcessThread , which identifies the main thread of the application (at least I could see). I looked through the list of “Windows Processes and Thread Functions” and again I did not see anything obvious (maybe OpenThread?).

Curious, does anyone know how the Threads window assigns a special category to the main theme?

+6
debugging multithreading visual-studio
source share
1 answer

The debugger starts debugging using CreateProcess using the DEBUG_PROCESS option. The main thread descriptor is returned in PROCESS_INFORMATION.hThread, so it is not guessed. Joining is a little more complicated, probably the first CREATE_THREAD_DEBUG_EVENT notification that he sees from WaitForDebugEvent after joining DebugActiveProcess ().

The source code for MDbg is available if you want to take a closer look.

+5
source share

All Articles