4

I have found an application which requests process information using wmi queries (all threads and more info on each thread). I modified this application to determine the CPU usage per thread. (if my application is called 'appy', then the threads are named 'appy/0', 'appy/1', ...)

My question: is there a way to easily identify these threads outside of an IDE or another debugging environment?

I know there is the NameThreadForDebugging method, but this isn't accessible outside the debugging environment.

Is there a way to assign your own thread id upon creating that thread? Or is the only way to know who is who (the threads) by creating a dictionary and write that dictionary to a file so it is externally accessible.

Thanks in advance!

4

1 回答 1

4

No, you cannot assign your own thread ID, the thread ID is assigned to a thread by the CreateThread function and cannot be changed during its lifetime. And as you said the only way to identify thread in the external application (not a debugger) is to share the thread identification with that application somehow.

However it's not necessary to share the information through a file, you can use a shared memory block for instance. It will be much more efficient than using files.

As the reference about thread ID you can take the remark by the GetCurrentThreadId function:

Until the thread terminates, the thread identifier uniquely identifies the thread throughout the system.

于 2012-05-04T07:30:17.633 回答