An example:
class Program
{
[DllImport("kernel32.dll")]
static extern int GetCurrentThreadId();
static void Main(string[] args)
{
// managed tid
var managed = System.Threading.Thread.CurrentThread.ManagedThreadId;
// os tid
var os1 = AppDomain.GetCurrentThreadId(); // deprecated according to ms, but if you need the os thread id, this IS the call to use
var os2 = GetCurrentThreadId();
var os3 = System.Diagnostics.Process.GetCurrentProcess().Threads[0].Id;
Console.WriteLine("tid managed = " + managed);
Console.WriteLine("");
Console.WriteLine("tid os1 = " + os1);
Console.WriteLine("tid os2 = " + os2);
Console.WriteLine("tid os3 = " + os3);
}
}
Program output:
tid managed = 1
tid os1 = 8028
tid os2 = 8028
tid os3 = 8028