Posted By: ploe | Aug 7th, 2008 @ 3:34 PM
page 1 of 1
Comments: 2 | Views: 857
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? Sad
As far as I know StackTrace only works with System.Threading.Thread and there's no way to get a list of those.

But you don't need all that. Attach a debugger to that program and break in, chances are that if that infinite loop is the only code running in the program the debugger will stop somewhere in that code. Even if there is some other code running you can simply inspect all threads to see what they're doing.
jh71283
jh71283
Throw new System.Beverage. OutOfCoffeeException​()
Try searching for ProcMon from Sysinternals (it will have been renamed by now as Mark Russinovich now works for microsoft)
page 1 of 1
Comments: 2 | Views: 857
Microsoft Communities