如果我在下面的示例中取消注释行,Wait()
我startNew.Result
将捕获AggregateException
. 如果这些代码行被注释,为什么我看不到任何异常?
class Program
{
static void Main(string[] args)
{
try
{
Task<int> startNew = Task.Factory.StartNew(() => int.Parse(""),
TaskCreationOptions.LongRunning);
//int result = startNew.Result;
//startNew.Wait();
Thread.Sleep(10000);
}
catch (AggregateException ex)
{
Console.WriteLine("Catched in aggregated");
}
catch (Exception)
{
Console.WriteLine("Catched in general");
}
Console.WriteLine("The end");
Console.ReadLine();
}
}