How to do it...

  1. Create a new method called MultipleThreadWait() in your Demo class. Then, create a second method called RunThread() with the private modifier that 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 Demo         {           public void MultipleThreadWait()           {                   }           private void RunThread(int sleepSeconds)           {                   }         }
In reality, you would probably not call the same method. You could, for all intents and purposes, call three separate methods. Here, however, for simplicity's sake, we will call the same method with different sleep durations.
  1. Add the following code to your MultipleThreadWait() method. You will notice that we are creating three tasks ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.