Main Site Documentation

Getting the current thread Id


#1

Simply attempting to get the thread id of the current thread, i.e.,


using System.Threading;
Debug.Print("Thread ID:  " + Thread.CurrentThread.ManagedThreadId.ToString());

but ManagedThreadId doesn’t appear to be available nor does Visual Studio reveal anything similar that would give me the thread id. Can I get it?

I’m using old stuff, Visual Studio 2010 with SDK 4.1 on the legacy Panda II.

In the big picture, I’m attempting to call different threads with a Timer call back. I’ve also failed to find delegate.GetInvocationList().


#2

In NETMF all timer events are fired within the same thread.
By this any thread callback must have finished before the next one is called.
The same thread might also be used for other things like interrupt events, …

While this does not answer your question, it might make it obsolete.


#3

create a thread like this and then get it’s ID:


var myThread = new Thread(myFunction);
myThread.Start();
Debug.Print("MyThread ID is: " + myThread.ManagedThreadId); 


#4

Jay Jay, I run into the same problem as with my code, i.e, Visual Studio doesn’t recognize ManagedThreadId. It does not compile and “ManagedThreadId” is flagged with the message, “System.Threading.Thread does not contain a definition for ManagedThreadId…” MS says it lives in the assembly mscorlib but that assembly is included in my program. I’m wondering if there is a problem with SDK 4.1?

Reinhard, yeah, that is why I’m writing code to spawn new threads for each callback but running into this weird problem as well as not finding Delegate.GetInvocationList() to allow me to run each registered callback on its own thread.


#5

I don’t think it exists in netmf 4.1. The documentation doesn’t show it.


#6

Thanks, Architect. I was wondering if I was making some mistake and looking around for definitive doc on what exactly is in 4.1. I suppose when the compiler says it ain’t there, it ain’t there, but if you could point me to some external documentation it might help me sleep. I’m now assuming Delegate.GetInvocationList() is also not in 4.1 so need to work around that in my work around for their crippled timer class OR throw away the Pandas and jump into 4.2.


#7

Sorry I missed the fact that you are using 4.1… please refer to this link for the API:

http://msdn.microsoft.com/en-us/library/bb417054.aspx

Cheers,
Jay.


#8

@ Matt5 - Usually there is some form of a “what’s new” document, but I was looking at the official 4.1 reference:

http://msdn.microsoft.com/en-us/library/ee436590.aspx

I would like to note that documentation sometimes has errors, so object browser in VS and F12 are the final authorities.


#9

Thanks for the link to MF SDK 4.1 reference, Jay and Architect. I will put it to use, e.g., I just found that ParameterizedThreadStart delegate doesn’t seem to be there either, nor in MF 4.2 and 4.3? So I’ve implemented a Timer class that maintains its own list of parameterless delegates to call and starts them on separate threads on period.