// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Threading; using System.Threading.Tasks; namespace AA { public class Program { public static void Dump(string id, string msg) { Console.WriteLine("{0,-6} : {1,-15} at {2} (thread {3})", id, msg, DateTime.Now.ToString("HH:mm:ss.fff"), Thread.CurrentThread.ManagedThreadId); } public async static Task Test(int n) { Dump("Task " + n, "starting"); await Task.Delay(1000); Dump("Task " + n, "running"); Thread.Sleep(1000); Dump("Task " + n, "returning"); } public static void Main(string[] args) { Dump("Main", "ready to call"); Task t1 = Test(1); Task t2 = Test(2); Task t3 = Test(3); Dump("Main", "calls completed"); Task.WaitAll(t1, t2, t3); Dump("Main", "all done"); Console.ReadKey(); } } }