exception details: A task was canceled.
只是在想为什么要加
TaskContinuationOptions.OnlyOnCanceled
OnlyOnCanceled
创建取消?
class Program
{
static void Main(string[] args)
{
Console.WriteLine("starting");
Task<int> t = Task.Run(() => 42)
.ContinueWith((i) =>
{
Console.WriteLine("Canceled");
return i.Result * 2;
}, TaskContinuationOptions.OnlyOnCanceled);
Console.WriteLine("ending");
try
{
Console.WriteLine("ret {0}", t.Result);
}
catch (AggregateException ae)
{
ae.Handle(ex => { Console.WriteLine("exception details: {0}",ex.Message);
return true;
});
}
Console.ReadLine();
}