SHARE
TWEET

Untitled

a guest Sep 19th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. namespace Chapter_1_Listing_1_12
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Task<Int32[]> parent = Task.Run(() =>
  11.             {
  12.                 var results = new Int32[3];
  13.                 new Task(() => results[0] = 0,
  14.                 TaskCreationOptions.AttachedToParent).Start();
  15.  
  16.                 new Task(() => results[1] = 1,
  17.                 TaskCreationOptions.AttachedToParent).Start();
  18.  
  19.                 new Task(() => results[2] = 2,
  20.                 TaskCreationOptions.AttachedToParent).Start();
  21.  
  22.                 return results;
  23.             });
  24.  
  25.             var finalTask = parent.ContinueWith(
  26.                 parentTask => {
  27.                     foreach (int i in parentTask.Result)
  28.                     {
  29.                         Console.WriteLine(i);
  30.                     }
  31.                 });
  32.             finalTask.Wait();
  33.         }
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top