An elegant / simple way to check whether internet is available or not.

Posted by Trainee4Life on Stack Overflow See other posts from Stack Overflow or by Trainee4Life
Published on 2010-03-16T05:47:45Z Indexed on 2010/03/16 5:56 UTC
Read the original article Hit count: 191

Filed under:
|

I did a quick search on how to check whether Internet is available or not. Most of them talked about making InterOp calls to wininet.dll.

One of the answers pointed towards System.Net.NetworkInformation namespace. Exploring the namespace I found a class Ping which could be used to pinging to our servers from code, and checking whether server is available or not.

What I want to ask is how this solution compares to other solutions?

Ping soPing = new Ping();
var soPingReply = soPing.Send("www.stackoverflow.com");
if (soPingReply.Status != IPStatus.Success)
{
    // SO not available
}

© Stack Overflow or respective owner

Related posts about .NET

Related posts about Windows