Developer, Former MVP, now at Microsoft - Best of 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
System.Diagnostics.ProcessThread
ProcessorAffinity
System.Threading.Thread
// Call this passing in 0 public static ProcessThread GetProcessThreadFromWin32ThreadId(Int32 threadId) { if (threadId == 0) threadId = ThreadUtility.GetCurrentWin32ThreadId(); foreach (Process process in Process.GetProcesses()) { foreach (ProcessThread processThread in process.Threads) { if (processThread.Id == threadId) return processThread; } } throw new InvalidOperationException("No thread matching specified thread Id was found."); }
ThreadUtility
[DllImport("Kernel32", EntryPoint = "GetCurrentThreadId", ExactSpelling = true)] public static extern Int32 GetCurrentWin32ThreadId();