Question: The following C# program ThreeJobs.cs performs three slow operations JobA, JobB, and JobC sequentially. The output of JobA is needed in order to run JobB.
The following C# program ThreeJobs.cs performs three "slow" operations JobA, JobB, and JobC sequentially. The output of JobA is needed in order to run JobB. Revise the program to run the operations asynchronously. You should start JobA and JobC concurrently, then start JobB as soon as the results from JobA are available. namespace ThreeJobs { internal class Program { static void Main(string[] args) { Console.WriteLine("Begin"); int na = JobA(1); Console.WriteLine("JobA " + na); int nb = JobB(na); Console.WriteLine("JobB " + nb); int nc = JobC(2); Console.WriteLine("JobC " + nc); Console.WriteLine("Done"); }
static int JobA(int n) { Task.Delay(2000).Wait(); return 2*n; } static int JobB(int n) { Task.Delay(1000).Wait(); return 3*n; } static int JobC(int n) { Task.Delay(2500).Wait(); return 4 * n; } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
