Reference to a Thread -> ThreadID?

  • Thread starter Thread starter Lucas Tam
  • Start date Start date
L

Lucas Tam

Hi all,

I'm currently storing a reference to the entire thread object in my
application. However, I'm wondering if there is a smaller object I can
point to such as an Integer ThreadID?

If there is such a thing as a ThreadID, is there a method I can use to
return the Thread object?

Thanks.
 
* Lucas Tam said:
I'm currently storing a reference to the entire thread object in my
application. However, I'm wondering if there is a smaller object I can
point to such as an Integer ThreadID?

If there is such a thing as a ThreadID, is there a method I can use to
return the Thread object?

Threads have IDs, but they are not exposed by the thread class.
Nevertheless, storing a reference to a thread object is very
lightweight.
 
The Managed Thread class does not expose any thread ID property neither any
handle property which one can use. However, the GetHashCode can be used to
uniquely identify a thread. Here's some more info on this:

http://msdn.microsoft.com/library/d...nagedunmanagedthreadinginmicrosoftwindows.asp

But ofcourse, thats not going to help you since there's no method in the
managed thread class of retrieving the Thread object from the hashcode (or
even from the threadid or thread handle) unless you store the
hashcode-thread pairs in a hashtable which defeats the whole purpose of
lightweight!

In anycase I don't think hanging onto a thread object is that 'heavy' as
such. Compared to some of the GDI+ objects, these are pretty ligthweight and
shouldn't be much of a problem.

hope this helps..
Imran.
 
Lucas,
I'm currently storing a reference to the entire thread object in my
application. However, I'm wondering if there is a smaller object I can
point to such as an Integer ThreadID?

On 32-bit systems, Object refernces are 32 bits, just like an int. So
you'll not save anything by using an int instead.



Mattias
 
(e-mail address removed) (Herfried K. Wagner [MVP]) wrote in
Nevertheless, storing a reference to a thread object is very
lightweight.

Thanks for the info : )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top