我可以得到我的c#应用程序中所有线程的堆栈跟踪吗?

我可以得到我的c#应用程序中所有线程的堆栈跟踪吗?

问题描述:

我在调试一个明显的并发问题在一个大型的应用程序,我在工作。有问题的bug仅在运行了许多(12+)小时后才会在某些低性能机器上显示,我从来没有在调试器中重现它。因为这个,我的调试工具基本上限于分析日志文件。

I'm debugging an apparent concurrency issue in a largish app that I hack on at work. The bug in question only manifests on certain lower-performance machines after running for many (12+) hours, and I have never reproduced it in the debugger. Because of this, my debugging tools are basically limited to analyzing log files.

C#使得很容易得到线程的堆栈跟踪抛出异常,但我想要在抛出异常时另外获取当前在我的AppDomain中执行的每个其他线程的堆栈跟踪。

C# makes it easy to get the stack trace of the thread throwing the exception, but I'd like to additionally get the stack traces of every other thread currently executing in my AppDomain at the time the exception was thrown.

这是否可能?

CodePlex上有一个工具叫做管理堆栈资源管理器(我相信源自微软)。它使用调试和分析API捕获运行的.Net应用程序中的线程的堆栈跟踪,而不需要修改应用程序。

There is a tool on CodePlex called Managed Stack Explorer (that I believe originated from Microsoft). It uses the debugging and profiling API to capture the stack traces of the threads in a running .Net application, without the need to modify the application.

您可以运行应用程序直到您遇到此问题,然后使用此工具分析它捕获所有正在运行的线程的当前堆栈跟踪。这种方法的好处是,您不必修改应用程序(检测它可能会改变它的行为),该工具是免费的。

You could run your application until you experience the issue, then analyse it using this tool to capture the current stack traces of all running threads. The benefit of this approach is that you leave your application unmodified (instrumenting it may change its behaviour), and the tool is free.