Is there any way to see the full stack trace across multiple threads?

▼魔方 西西 提交于 2019-12-06 09:06:15

问题


In C# multi-threaded programming, when method A() calls method B() in a new thread, e.g. by using something like this:

Task A()
{
    // ...

    // I want B to run in parallel, without A() waiting for it.
    Task.Factory.StartNew(B); 
}

void B()
{
     // I attach a debugger here to look at the Call Stack.
     // But that is empty and I can't see that A() actually called it (logically).

     // Also Environment.StackTrace is pretty much empty of that path.
}

In other words inside method B() the stack trace doesn't know anything about the call path to method A() which in turn triggered execute of method B().

Is there any way to see the full logical stack trace, so e.g. in the case of an exception in B() you can see the full story to know A() in effect called it?


回答1:


In general the answer is No, as StackTrace by definition cannot contain information from other stack. However, if you debugging your application in Visual studio, it do some work for you (this is C++, but it's similar for all the languages):

Here, external code is dimmer than your, and you can review some "parent" thread information. However, usually this screen isn't much helpful. Visual studio creates vshost.exe file for gather as much debug information as possible.

Also, if you create the task withh attaching them to parent, and there is some exception, you'll get full stacktrace with exception's ToString method, but still it's not exactly what you want.



来源:https://stackoverflow.com/questions/41908593/is-there-any-way-to-see-the-full-stack-trace-across-multiple-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!