Is there a way to get a Thread's ThreadName from a ThreadId? (from say, a ThreadID like 10, or 15, etc.)
There is the way of current thread getting: Thread t = Thread. currentThread(); After you have got Thread class object (t) you are able to get information you need using Thread class methods.
In the run() method, we use the currentThread(). getName() method to get the name of the current thread that has invoked the run() method. We use the currentThread(). getId() method to get the id of the current thread that has invoked the run() method.
In Python 3.3+, you can use threading. get_ident() function to obtain the thread ID of a thread. threading. get_ident() returns the thread ID of the current thread.
Thread Id is a long positive integer that is created when the thread was created. During the entire lifecycle of a thread, the thread ID is unique and remains unchanged. It can be reused when the thread is terminated.
Not in managed code. You can't even get a list of Thread
objects for the current process, as far as I'm aware. You can get the ProcessThread
s with Process.Threads
and ProcessThread
provides an Id
property, if that helps you... but a ProcessThread
doesn't have a name as far as I can tell :(
The best information that I could find is here:
http://www.mail-archive.com/[email protected]/msg07369.html
That doesn't seem too helpful, though. It seems that there is no good way to do this, short of you changing the code to maintain a list (or dictionary) of all of your application's threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With