I have a Task<T> t1
. I want to run another Task t2
after t1
completes. I choose to use the .ContinueWith
method of t1
.
void ThenFrob(Task<Frobber> t1) {
t1.ContinueWith(frobber => frobber.Frob())
}
Except, I cannot do this, because the Action parameter of Task<T>
is passed the Task<T>
, rather than T
itself. Instead, I have to take the result of the parameter passed into my action to interact with it.
void ThenFrob(Task<Frobber> t1) {
t1.ContinueWith(frobberTask => {
var frobber = frobberTask.Result;
frobber.frob();
});
}
If the point of ContinueWith is to add another action to the chain, why wouldn't the language designers have simply passed the result of the previous task? Or, in the case of a non-generic Task expected a parameterless action?