By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

Reference to a Thread -> ThreadID?

P: n/a
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 (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
* Lucas Tam <RE********@rogers.com> scripsit:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
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/de...oftwindows.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 Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
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 (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #3

P: n/a
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #4

P: n/a
hi***************@gmx.at (Herfried K. Wagner [MVP]) wrote in
news:O7*************@TK2MSFTNGP11.phx.gbl:
Nevertheless, storing a reference to a thread object is very
lightweight.


Thanks for the info : )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.