When should I use
Task task1 = Task.Factory.StartNew (() => {...})
.ContinueWith (ant => Console.Write ("2"));
vs
Task task1 = Task.Factory.StartNew (() => {... });
Task task2 = task1.ContinueWith (ant => Console.Write ("2"));
When should I use
Task task1 = Task.Factory.StartNew (() => {...})
.ContinueWith (ant => Console.Write ("2"));
vs
Task task1 = Task.Factory.StartNew (() => {... });
Task task2 = task1.ContinueWith (ant => Console.Write ("2"));
It means the same, except for you'll have a reference to the second task now. You can use the second option if the first task needs some processing before executing the tasks all together. An example is to add another
var task3 = task1.ContinueWith()
so task two and three will execute concurrently, but only if the first task is done processing. Actually it should be:Note I replaced
task1
totask2
. Starting either Task will causetask1
to start first.