简体   繁体   English

找出多线程C#程序卡在哪里

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

I have written a C# program having some thousand lines and several threads. 我写了一个C#程序,有几千行和几个线程。 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. 执行工作正常几个小时/天,直到在Windows服务器上运行的应用程序开始减慢所有内容(其他程序/ Web服务器),因为它突然开始耗尽大约50-80%的CPU。

I assume that it is stuck in some while-loop, but I do not know where exactly. 我认为它停留在某些while循环中,但我不知道究竟在哪里。 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? 有没有人知道让Visual Studio监视当前CPU负载以显示它用完的地方的好方法?

Oh, how I love Managed Stack Explorer. 哦,我喜欢Managed Stack Explorer。 http://mse.codeplex.com/ for most versions of .NET and https://github.com/vadimskipin/MSE for 4.0 http://mse.codeplex.com/适用于大多数.NET版本和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. 哦,当它让我在几分钟内找到我一直在寻找的东西时,我感到高兴。

当发生这种情况时,您可以使用Perfview(http://www.microsoft.com/en-us/download/details.aspx?id=28567)捕获并分析ETL跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM