You are just starting your three subtasks, but you are not waiting for their completion. Adapt it like this:
var task1 = new Task(() => results[0] = 0, TaskCreationOptions.AttachedToParent); var task2 = new Task(() => results[1] = 1, TaskCreationOptions.AttachedToParent); var task3 = new Task(() => results[2] = 2, TaskCreationOptions.AttachedToParent); task1.Start(); task2.Start(); task3.Start(); task1.Wait(); task2.Wait(); task3.Wait();
Also note that with your current code you can still show 0 1 2 (not 1 2 3 way), since it is not detected when subtasks work / end. It may also depend on the configuration of the assembly (debug / release).
Chips_100
source share