Wojciech Kmita
Wojciech Kmita

Reputation: 259

Threading: Thread.CurrentThread.Name and Thread.CurrentThread.ManagedThereadId

I was trying to identify some threads by assigning names to them (property: System.Threading.Thread.CurrentThread.Name) but then I realized I could use the System.Threading.Thread.CurrentThread.ManagedThreadId. My question is: if I assign "Thread1" in the property CurrentThread.Name and the CurrentThread.ManagedThreadId would be "1", will this always be true? or the threadpool can assign different ManagedThreadId to the thread with the name "Thread1"?

Upvotes: 2

Views: 9581

Answers (1)

Tudor
Tudor

Reputation: 62459

MSDN states:

The value of the ManagedThreadId property does not vary over time, even if unmanaged code that hosts the common language runtime implements the thread as a fiber.

So I wouldn't worry about the correspondence thread name -> managed thread id breaking.

Upvotes: 2

Related Questions