public static void Main() { var t = Task.Run(() => { throw new Exception("aa"); }); Task.Factory.ContinueWhenAll(new Task[] { t }, (tt) => { Thread.Sleep(1000); Console.WriteLine(tt[0].Exception.InnerException.Message); }); Task.WhenAll(t).ContinueWith(tt => { if (tt.Exception != null) { Thread.Sleep(1000); Console.WriteLine(tt.Exception.InnerException.Message); } }); Console.WriteLine("over一秒后"); Console.ReadKey(); }
非常简单的一个例子,一看就知道咋肥事了。
打印结果:
over 一秒后
aa
aa