Hello everyone,
I am migrating from C++ to C#. And I am debugging a multi-threaded program and I need to print out the thread ID. In C++, I am using GetCurrentThreadID method, but in C#, I only find Thread.CurrentThread.ManagedThreadId.
My questions are,
1.
Does Thread.CurrentThread.ManagedThreadId have the same effect and can serve my purpose?
2.
I am confused about what means "ManagedThreadId", does there is some peer called "NonManagedThreadId"?
thanks in advance,
George

Ryan AlfordRank #1,411 · 1.2K reputationPosted Jun 4, 2008, 5:09 AM EDT
if you would have looked up GetCurrentThreadID on MSDN, it would have given you the answer.
http://msdn.microsoft.com/en-us/library/system.appdomain.getcurrentthreadid.aspx
"AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. http://go.microsoft.com/fwlink/?linkid=14202"
George GeorgeRank #1,736 · 870 reputationPosted Jun 4, 2008, 9:44 PM EDT
Thanks Ryan!
My application is pure C# application, and I want to dump thread ID to detect the behavior of each thread, so that I can find deadlock/re-entrance/how many times a thread enters a specific method, something like this.
I think from the document and your help, ManagedThreadId could serve my purpose, right?
regards,
George
Ryan AlfordRank #1,411 · 1.2K reputationPosted Jun 5, 2008, 5:51 AM EDT
George GeorgeRank #1,736 · 870 reputationPosted Jun 5, 2008, 4:38 PM EDT
Hi Ryan,
What means "unique("stable")"?
regards,
George
Ryan AlfordRank #1,411 · 1.2K reputationPosted Jun 6, 2008, 5:35 AM EDT
"stable" was taken from the MSDN page where it states to use the ManagedThreadID to get a "stable" ID of a thread......"stable" meaning a unique ID that you can count on ALWAYS being unique.
George GeorgeRank #1,736 · 870 reputationPosted Jun 9, 2008, 1:08 AM EDT
Sorry Ryan,
My English is not good. From your previous reply, I think you mean unique is an C# keyword, but from MSDN search, it is not. Could you help to clarify your previous points please?
regards,
George
Ryan AlfordRank #1,411 · 1.2K reputationPosted Jun 9, 2008, 5:37 AM EDT
when I said "unique", I meant the English language word UNIQUE.
George GeorgeRank #1,736 · 870 reputationPosted Jun 9, 2008, 6:41 PM EDT
Thanks Ryan,
Question answered.
regards,
George