I am using ThreadPool
to execute a set of tasks in a windows service. The service spawns new threads every 10seconds. I would like to record the name of the thread that picked up a particular task from the database. Is it possible to get the name of the thread?
The easiest way for this will be from inside the context of each thread as you have the CurrentThread property available and all the properties that are attributed to a thread:
System.Threading.Thread.CurrentThread.Name
Like a previous poster has mentioned though, how meaningful this will be from with in a thread pool, I am not sure.
I don't know if ThreadPool threads are assigned a meaningful Name, but you should always be able to use the ManagedThreadId of the CurrentThread for debugging/logging purposes.
Don't try and change thread state when using threads from the pool. These threads don't belong to you, they belong to the runtime. You don't want to be changing stuff you don't own.
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