none
What is the fastest and most efficient way to check internet connection

    General discussion

  • Hi,

    What is the fastest and most efficient way to check the internet connection in Silverlight 5 OOB application?

    The below code, I dont think is entirely correct as it only checks that the computer is connected to a router?

                        if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
                        {
                            //no network connection
                        }
                        else
                        {
                            //network connection
                        }

    Tuesday, October 02, 2012 2:28 PM

All replies

  • Hi..

    I still wonder for a solution of what the best and fastest way would be to check if there is an internet connection for an OOB application in Silverlight 5. I have googled but can´t see to find any good solution on this?

    Friday, October 05, 2012 7:40 PM
  • What are you trying to achieve?  Remember that the connection could go away at any point in time so even if you have code that looks like this

    if (SubNanoSecondCheckIfInternetIsAvailable()) {
       DoSomeOperationWhichNeedsTheInternet();
    }

    The internet connection could fail between the test and the protected code causing it to fail.  The test may pass but the particular internet location required may not be available.  The security requirements at the target site may have changed, unannounced (grrr, this happened to me three weeks ago).  Or many other things

    Bottom line is that you will need to have error handling in place for every action which depends on internet access anyway so do you gain much by having a 'Super duper mega high speed internet availability checking' routine?

    If your application really needs a particular internet location to be available then I don't think you could do much better than pinging the location with timeout handling.  It won't be fast and it only tells you about the state of the target at the instant the test is made.

    Saturday, October 06, 2012 1:45 AM
  • Thanks for answer,

    I do have a location (server) that I in another code check for internet connection which has it´t own logic.

    However in the application, I have a function and statistic where I need to know if the internetconnection was avaliable at a certain time. I will only need to check the connection once every 60 seconds. The internet could ofcourse be lost the other 59 seconds but the function doesn´t need to be exactly accurate in this scenario.

    For example I would go about to check "google.com, yahoo.com, bing.com" in a loop and if all of those sites aren´t avaliable, I will state that no internetconnection is avaliable.

    But I dont wonder how to check if www.google.com has a connection with code?

    Saturday, October 06, 2012 1:30 PM