I'm confused about the TPL ContinueWith
method. I don't understand why it's needed. Here's an example from MSDN that shows how to use ContinueWith
:
static void SimpleContinuationWithState()
{
int[] nums = { 19, 17, 21, 4, 13, 8, 12, 7, 3, 5 };
var f0 = new Task<double>(() => nums.Average());
var f1 = f0.ContinueWith(t => GetStandardDeviation(nums, t.Result));
f0.Start();
Console.WriteLine("the standard deviation is {0}", f1.Result);
}
It seems that I can remove the ContinueWith
call without changing the results at all:
static void SimpleContinuationWithState()
{
int[] nums = { 19, 17, 21, 4, 13, 8, 12, 7, 3, 5 };
var f0 = new Task<double>(() => GetStandardDeviation(nums, nums.Average()));
f0.Start();
Console.WriteLine("the standard deviation is {0}", f0.Result);
}
This standard deviation example must be a contrived example, but I can't think of a reason to ever use ContinueWith. (unless some library call created the Task instead of me) In every case, can't I pull the ContinueWith call into the original Task? It'll still run asynchronously. There must be something I'm not understanding.