Posts

Showing posts from July, 2011

Using WinDBG/CDB and SOS to find a thread given a ManagedThreadId

CDB and SOS have more power than most people realize, I’ll use this post to show some some handy cdb/sos tricks while at the same answering the simple question of which thread a ManagedThreadId maps to. At the end of this post you’ll be able to: Map a ManagedThreadId to the correct thread ordinal Use CDB to convert from decimal to hex Pipe CDB commands through pipeline commands like findstr Full source for the simple app below can be found here . In the below app we want to figure which thread we’re running on so we can inspect the stack. internal class Program { private static void SleepForever() { Thread.Sleep(Int32.MaxValue); } static void Main(string[] args) { const int countThreadsToStart = 20; foreach (var unused in Enumerable.Range(0, countThreadsToStart)) { // Instantiate thread that prints and stores its ManagedThreadId. new Thread(() => {