>However, in practice, is the Int32 returned by GetHashCode unigue?
On v1.x of the CLR, where there is a 1:1 mapping between managed and
native thread, yes. At least as long as the thread is alive, thread
IDs can be re-used by other threads later.
>This would imply that there is a theoretical limit of Int32.MaxValue
>threads;
The same is true for whatever other 32-bit signed number you could get
to identify the thread. I don't see it as a problem, you're not going
to have 2 billion threads running.
>Any other suggestions?
Does it have to be a numeric value? If not, the easises way to
identify a thread inside managed code is with the
System.Threadinf.Thread reference.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
David Levine - 25 May 2004 00:10 GMT
> Does it have to be a numeric value? If not, the easises way to
> identify a thread inside managed code is with the
> System.Threadinf.Thread reference.
Is this a typo? I can't find any info on a Threadinf object/class. What
object/value are you referring to here? thanks
Mattias Sj?gren - 25 May 2004 20:28 GMT
>> System.Threadinf.Thread reference.
>
>Is this a typo?
Yes, Threadinf should be Threading. Sorry about that.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Plausible Indirection - 25 May 2004 19:01 GMT
Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote in message news:<ulaW9$bQEHA.368@TK2MSFTNGP09.phx.gbl>...
> >However, in practice, is the Int32 returned by GetHashCode unigue?
>
> On v1.x of the CLR, where there is a 1:1 mapping between managed and
> native thread, yes. At least as long as the thread is alive, thread
> IDs can be re-used by other threads later.
I'm trying to come up with a solution that has good odds of surviving
the migration to the next framework version.
> >Any other suggestions?
>
> Does it have to be a numeric value? If not, the easises way to
> identify a thread inside managed code is with the
> System.Threadinf.Thread reference.
No, I guess my background in C has made me biased towards integers,
but any type that can be converted to a string meaningfully will do.
> Mattias
In any case, a little more careful reading (while I was trying to
figure out if you meant a reference pointer on a thread) (RTFM in the
first place.) on my part yielded the answer. From the MSDN Thread
class description:
"GetHashCode provides identification for managed threads. For the
lifetime of your thread, it will not collide with the value from any
other thread, regardless of the application domain from which you
obtain the value."
So, GetHashCode will work fine for my purposes. Providing this
doesn't change at 2.x (or whatever it's called).
Thanks,
Chris