在C#多线程编程中,当方法A()
在新线程中调用方法B()
时,例如,通过使用这样的事情:有没有什么方法可以在多个线程中看到完整的堆栈跟踪?
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.
}
在里面方法换句话说B()
堆栈跟踪不知道呼叫路径方法A()
这反过来又触发execute方法B()
的东西。
是否有任何方法可以看到全逻辑堆栈跟踪,例如,在B()
的例外情况下,您可以看到完整的故事,知道A()
实际上被称为它吗?
@SimonPrice,这就是一般调试多线程程序的方法。 OP正在寻找一种方法来找出哪个线程(和调用堆栈到那个点)开始另一个线程/计划一个任务,如果该任务抛出异常。有什么更具体的? –
我已经更新了更多的细节问题。您可以在Visual Studio中轻松创建这个场景以自行查看。 – Paymon
我在UWP应用程序中测试这个,如果有帮助的话。 – Paymon