From the course: C# Essential Training 2: Generics, Collections, and LINQ
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Solution: Task management - C# Tutorial
From the course: C# Essential Training 2: Generics, Collections, and LINQ
Solution: Task management
- [Instructor] In this challenge, we need to use tasks to make some asynchronous calls. We see on lines 11 through 17, or 18, that our Solver class has these asynchronous MinAsync and MaxAsync operations that take an array of numbers and return a Task<int>. So these are asynchronous functions. Maybe we're calling out to something over the network to actually do this highly complex work, and so in our solution, we then need to be able to manage those two tasks. So I want to say I've got a Task<int>, 'cause that's the return type, so I'm going to say tMin =, and now I'll do solver.MinAsync, pass in the numbers. Likewise, I've got a Task<int> tMax = solver.MaxAsync, pass in the numbers. So I have a reference to those tasks that now are off and running, so now I can choose to Task.WaitAll, and I can pass in tMin and tMax. And when those are done, I now have the results in the Task that I can return, so I've got min and…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.