December 2019
Intermediate to advanced
346 pages
9h 8m
English
We can wait for multiple tasks and chains in continuation code that will run when any of the tasks are completed successfully:
private static void ContinueWhenAny() { int number = 13; Task<bool> taskA = Task.Factory.StartNew<bool>(() => number / 2 != 0); Task<bool> taskB = Task.Factory.StartNew<bool>(() => (number / 2) * 2 != number); Task<bool> taskC = Task.Factory.StartNew<bool>(() => (number & 1) != 0); Task.Factory.ContinueWhenAny<bool>(new Task<bool>[] { taskA, taskB, taskC }, (task) => { Console.WriteLine((task as Task<bool>).Result); } ); }
As shown in the preceding code, we have three different pieces of logic to find out whether a number ...
Read now
Unlock full access