How to do it...

  1. In the Demo class, add a method called CheckClientMachinesOnline(), which takes as parameters a List<string> collection of IP addresses and an integer that specifies the minimum number of machines required to be online. Add a second method called MachineReturnedPing(), which will receive an IP address to ping. For our purpose, we will just return false to mimic a dead machine (the ping to the IP address timed out):
        public class Recipes         {           public void CheckClientMachinesOnline(List<string> ipAddresses,             int minimumLive)           {                   }              private bool MachineReturnedPing(string ip)             {                         return false;           }          }
  1. Inside the CheckClientMachinesOnline() method, add the Parallel.ForEach loop and create the ParallelOptions variable that will ...

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.