Getting Current Native Thread
Posted
by Ricardo Peres
on ASP.net Weblogs
See other posts from ASP.net Weblogs
or by Ricardo Peres
Published on Tue, 15 Feb 2011 10:55:47 GMT
Indexed on
2011/02/15
15:26 UTC
Read the original article
Hit count: 394
The native OS threads running in the current process are exposed through the Threads property of the Process class. Please note that this is not the same as a managed thread, these are the actual native threads running on the operating system.
In order to get a pointer to the current executing thread, we must use P/Invoke. Here's how we do it:
[DllImport("kernel32.dll")] public static extern UInt32 GetCurrentThreadId(); UInt32 id = GetCurrentThreadId(); ProcessThread thread = Process.GetCurrentProcess().Threads.Cast().Where(t => t.Id == id).Single();
© ASP.net Weblogs or respective owner