From the course: Asynchronous Programming in C#
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Solution: Create and continue a task - C# Tutorial
From the course: Asynchronous Programming in C#
Solution: Create and continue a task
(upbeat music) - [Instructor] The first step to solving this challenge is to write a function to calculate factors for a given number. I'll create a new function named CalculateFactors that returns a list of integers and takes a single integer as a parameter. In the body of the function, I'll first instantiate a new list of integers to store the factors I find. I'll then use a basic for loop from one to the number passed in as a parameter. Each time through the loop, I'll use the modulo operator to see if dividing our number by the loop variable produces a zero remainder. If it does, then it's a factor and I'll add it to the list. At the end of the function, I'll just return the list. Let's now execute the function with a task on a background thread. I'll first add a call to Console.WriteLine just so we know when the program is starting. I'll then declare a new variable to store the integer I'll pass to the function.…