22

For ManagedThreadID, MSDN says:

Gets a unique identifier for the current managed thread.

In what context does "unique" apply?

Is this unique per process?
Per application domain?
Per machine?
Per .NET runtime? (if I have both MS.NET and Mono running)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jimmy
  • 89,068
  • 17
  • 119
  • 137

2 Answers2

20

Thread ID is unique per process during a thread's lifecycle. After the thread terminates, its number can be reused.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dewfy
  • 23,277
  • 13
  • 73
  • 121
  • 2
    See http://rocksolid.gibraltarsoftware.com/development/logging/managed-thread-ids-unique-ids-that-arent-unique for proof – Lars Truijens Jul 26 '12 at 09:04
2

Since threads from the ThreadPool also have to honour this property, and there is one ThreadPool per process (as stated in this MSDN article), I would think that the ManagedThreadId is most likely unique per process.

adrianbanks
  • 81,306
  • 22
  • 176
  • 206