Explicit Task Parallism C# with Example



Explicit Task Parallism C# with Example

private static void explicitTaskParallism() 
{ 
Thread.CurrentThread.Name = "Main"; 
// Create a task and supply a user delegate by using a lambda expression. 
Task taskA = new Task(() => Console.WriteLine($"Hello from task {nameof(taskA)}.")); 
Task taskB = new Task(() => Console.WriteLine($"Hello from task {nameof(taskB)}.")); 
// Start the task. 
taskA.Start(); 
taskB.Start(); 
// Output a message from the calling thread. 
Console.WriteLine("Hello from thread '{0}'.", 
Thread.CurrentThread.Name); 
taskA.Wait(); 
taskB.Wait(); 
Console.Read(); 
} 

0 Comment's

Comment Form