本章内容其实挺重要的,但是现在我工作中还没怎么遇到,应该是我还没想到的关系吧~
ContinueWith是Task根据其自身状况,决定后续应该作何操作。也就是说,在运行完task后,会执行task.continuewith(XX)中的XX语句,但是是否执行、如何执行等需要看task的运行情况。
static int TaskMethod(string name, int seconds)
{
Console.WriteLine("Task Method : Task {0} is running on a thread id {1}. Is thread pool thread: {2}",
name, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.IsThreadPoolThread);
Thread.Sleep(TimeSpan.FromSeconds(seconds));
return 42 * seconds;
}
var firstTask = new Task<int>(() => TaskMethod("第一个任务", 3));
firstTask.ContinueWith(t => Console.Wri
因篇幅问题不能全部显示,请点此查看更多更全内容