Sometimes, we need to create multiple threads. Before we can continue, however, we need to wait for these threads to complete doing whatever they need to do. For this, the use of tasks is best suited.
Make sure that you have added the using System.Threading.Tasks;
statement to the top of your Recipes
class.
Create a new method called
MultipleThreadWait()
in yourRecipes
class. Then, create a second method calledRunThread()
with theprivate
modifier, which takes an integer of seconds to make the thread sleep. This will simulate the process of doing some work for a variable amount of time:public class Recipes { public void MultipleThreadWait() { } private void RunThread(int sleepSeconds) { } }