Task异常捕捉

public static Task Catch(this Task task,Action<Exception> callback)
{
return task.ContinueWith<Task>(delegate (Task t)
{
if (t != null && t.IsFaulted)
{
AggregateException exception = t.Exception;
Trace.TraceError("Catch exception thrown by Task: {0}", new object[]
{
exception
}); 
callback(exception.InnerException);
}
return t;
}).Unwrap();
}
原文地址:https://www.cnblogs.com/lvzhenHome/p/13711536.html