I have a C# server application that's stuck in a loop somewhere; after a while the process just constantly uses 13% CPU (1 core). I'm pretty sure it's one of my ThreadPool threads that's doing this; some command sent by the client eventually triggers this infinite loop.
I've looked at the StackTrace object as a stack trace would definately help me find the code that's causing this. There is a constructor that allows me to pass in a Thread object to get the stack trace of the passed in thread however I don't have a Thread object because it's a ThreadPool thread.
Do you know any way that I can get a stack trace of a ThreadPool thread?
I am able to identify the thread that is looping by printing out all the threads and finding the one that has taken up the most CPU time. However I can't seem to use the information from the code below to get a stack trace.
foreach (System.Diagnostics.ProcessThread thread in System.Diagnostics.Process.GetCurrentProcess().Threads) {
Console.WriteLine("ID: {0}", thread.Id);
Console.WriteLine("Start Time: {0}", thread.StartTime);
Console.WriteLine("State: {0}", Enum.GetName(typeof(System.Diagnostics.ThreadState), thread.ThreadState));
Console.WriteLine("Total Proc Time: {0}\n", thread.TotalProcessorTime);
}
Any suggestions?
