I have a complex system with several threads. sometimes i see the application in 100% cpu and force to restart the system. I have no idea which thread caused it and which code caused it.
I need something that will give me the state of each thread in the system (i.e. in which line the thread is now) so i can find which code causes the 100% CPU

(in java you have the thread dump kill -3 which gives you the state of each thread)

With good reason. Process Explorer allows you to see per-thread CPU usage. (Double-Click on the process, then look at the Threads tab.) Unfortunately, you do not get much more information there.. it is most likely only a starting point.
–
Andreas ReiffJul 17 '12 at 13:49

As for me - this is the first thing to do! Thanks man for the suggestion
–
chopikadzeNov 18 '12 at 18:37

I have found that in cases like this one of the best tools around these days in Microsoft's intellitrace. This allows for historical debugging & will give you the state of all threads etc. when you break execution.

Unfortunatly its only available in Visual Studio 2010 Ultimate edition, but if this is a really critical issue and you don't have this edition you could always download a 30 day evaluation.

Use VS debugger to attach to your process, and then press the "break" (pause symbol) to break execution. In this state, you can open the Debug window called "Threads" which should give you the state of each thread, and which line they're currently executing. It also helps at this point to give explicit names to your threads when debugging them.

I find that 99% of the time (at least for me) its because I accidentally make a loop infinite when I don't mean to make it so or there should be at least a few milliseconds of sleep before the the loop continues.