Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out where a multi-threading C# program is stuck

I have written a C# program having some thousand lines and several threads. Execution works fine for several hours/days until the application, which is running on a Windows server, starts to slow everything (other programs/web server) down as it suddenly begins to use up about 50-80% of the CPU.

I assume that it is stuck in some while-loop, but I do not know where exactly. It would already be a help to know which thread uses up the largest share of the system resources. As there is not any exception thrown, I do not see any direct possibility to find out.

The code has already been inspected but I did not find any significant/obvious programming mistakes.

Does anybody know a good way to let Visual Studio monitor the current CPU-load in order to show where it is used up?

like image 404
1' OR 1 -- Avatar asked Jan 15 '23 17:01

1' OR 1 --


2 Answers

Oh, how I love Managed Stack Explorer. http://mse.codeplex.com/ for most versions of .NET and https://github.com/vadimskipin/MSE for 4.0

Point it at your running application, and it snapshots the stacks of each thread. After looking at a few snapshots, you'll work out where the problem is. Oh, the nastiness of the problem I was facing when I first learnt of this. Oh the joy when it let me find what I'd been hunting for days in just a few minutes.

like image 116
Jon Hanna Avatar answered Jan 28 '23 02:01

Jon Hanna


You can use Perfview (http://www.microsoft.com/en-us/download/details.aspx?id=28567) to capture and the analyse ETL traces when this happens.

like image 28
Feng Yuan Avatar answered Jan 28 '23 02:01

Feng Yuan