[ACCEPTED]-Getting the thread ID-multithreading

Accepted answer
Score: 15

Use GetCurrentThreadId() or ManagedThreadId() to 2 get the thread ID:

int threadID = (int)AppDomain.GetCurrentThreadId();
int managedThreadId = Thread.CurrentThread.ManagedThreadId;
Console.WriteLine("ThreadId = " + threadID);
Console.WriteLine("ManagedThreadId = " + managedThreadId);

Have a look at Stack Overflow 1 question Getting the thread ID from a thread.

Score: 3

You can use WinApi functions GetCurrentThreadId and GetThreadId

0

Score: 2

If you are seeing a different thread ID 7 in your live application as opposed to when 6 you debug in Visual Studio, that is just 5 what you should expect to see, right?

When 4 running in the debugger, you are effectively 3 running the application in the debugger 2 host which will have different threads than 1 just running the application on its own.

More Related questions