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
George GeorgePosted Jun 9, 2008, 10:41 PM
Thanks Ryan,
Question answered.
regards,
George
Ryan AlfordPosted Jun 9, 2008, 9:37 AM
when I said "unique", I meant the English language word UNIQUE.
George GeorgePosted Jun 9, 2008, 5:08 AM
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 AlfordPosted Jun 6, 2008, 9:35 AM
"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 GeorgePosted Jun 5, 2008, 8:38 PM
Hi Ryan,
What means "unique("stable")"?
regards,
George
Ryan AlfordPosted Jun 5, 2008, 9:51 AM
George GeorgePosted Jun 5, 2008, 1:44 AM
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 AlfordPosted Jun 4, 2008, 9:09 AM
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"