Invoking methods or actions in parallel (Parallel region)
static void Main()
{
string [] urls =
{
"www.stackoverflow.com",
"www.google.net",
"www.facebook.com",
"www.twitter.com"
};
System.Threading.Tasks.Parallel.Invoke(
() => PingUrl(urls[0]),
() => PingUrl(urls[1]),
() => PingUrl(urls[2]),
() => PingUrl(urls[3])
);
}
void PingUrl(string url)
{
var ping = new System.Net.NetworkInformation.Ping();
var result = ping.Send(url);
if (result.Status == System.Net.NetworkInformation.IPStatus.Success)
{
Console.WriteLine(string.Format("{0} is online", url));
}
}