看起来你在赏金上浪费了你的声望,因为这个问题之前已经被问过几次,例如:
我记得这个问题曾经有几个赏金,但没有比这更进一步的参考:
或者在这个SO问题中:
参考答案:
另一个类似的SO问题:
我发现Daniel Moth在Visual Studio 2010中关于并行调试(Parallel Stacks,Parallel Tasks)的参考资料集非常有帮助。
更新:
运行您的代码后
using System;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Foo();
}
public static async void Foo()
{
await Bar();
}
public static async Task Bar()
{
try
{
await TaskEx.Delay(2000);
throw new Exception();
}
catch (Exception)
{
throw new Exception("This is Excptn in Bar() method");
}
}
}
}
在VS2010+Async CTP调试模式(F5)中,我清楚地看到了我的标识异常消息“This is Excptn in Bar() method”:
无论如何,在堆栈跟踪(局部窗口)中,即使没有任何附加标记(使用自定义消息捕获并重新抛出异常),它也被识别为ConsoleApplication1.Program.<
Bar>,即在上述代码中将Bar()方法替换为:
public static async Task Bar()
{
await TaskEx.Delay(2000);
throw new Exception();
}
我在堆栈跟踪中看到异常是在ConsoleApplication1.Program.<Bar>
中抛出的:
+ $exception
{System.Exception: Exception of type 'System.Exception' was thrown.
Server stack trace:
at ConsoleApplication1.Program.<Bar>d__3.MoveNext() in R:\
Exception rethrown at [0]:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at ConsoleApplication1.Program.<Foo>d__0.MoveNext() in R:\
Exception rethrown at [1]:
at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.<SetException>b__1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()} System.Exception
d_12()
,我可以使用 ILSpy 工具反编译程序集并禁用 await 支持来找出它所在的方法。我需要的是一种能够为我执行该任务的工具。 - Richard Szalay