Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the thread ID [duplicate]

Possible Duplicate:
C#/.NET: How to get the thread id from a thread?

How I can get the same thread ID as I see it in Visual Studio?

I have tried to use Thread.CurrentThread.ManagedThreadId, but I am getting different numbers.

I am getting 35, 38, 39, etc., but in Visual Studio I have 10596, 893, etc...

like image 601
Night Walker Avatar asked Jun 23 '11 08:06

Night Walker


2 Answers

Use GetCurrentThreadId() or ManagedThreadId() to 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 question Getting the thread ID from a thread.

like image 162
Bibhu Avatar answered Oct 20 '22 16:10

Bibhu


You can use WinApi functions GetCurrentThreadId and GetThreadId

like image 20
Stecya Avatar answered Oct 20 '22 17:10

Stecya