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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.