Parallel.For

suggest change

An example that uses Parallel.For to ping a given array of website URLs.

static void Main()
{
    string[] urls = 
    {
        "www.stackoverflow.com", 
        "www.google.net", 
        "www.facebook.com", 
        "www.twitter.com"
    };

    System.Threading.Tasks.Parallel.For(0, urls.Length, i => PingUrl(urls[i]));
}

static 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));
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents