-1

I know there are many ways of doing it, I've read the SO posts.

I do not want to access a website, or externally if there is internet.

Is there a way to check internet status by checking the network card? In other words, when the laptop shows internet bars etc or computer itself shows "connected".

This method causes my code to be stuck:

private bool checkInternetStatus()
{
    try
    {
        using (var client = new WebClient())
            using (client.OpenRead("http://google.com/generate_204")) 
                online = true;
            //  Print("Connection estabished");
                return true; 
    }
    catch
    {
        online = false;
        Print("No internet connection");
        return false;
    }
}
lakersfan
  • 71
  • 5
  • Try that with a very short connection timeout. My guess is that the web client defaults to no timeout -- i.e. indefinite, wait forever, hence the code is stuck. –  Jun 21 '20 at 17:55
  • I would rather not use the webclient way. Regardless, do yo have a sample of what you mean so I can try out? Thank you. – lakersfan Jun 21 '20 at 18:01
  • Ok, I can't help you with a non-web way. The timeout you can look up in the API docs. –  Jun 21 '20 at 18:02

1 Answers1

0

You could use Ping, programmatically, in C#. No web client needed.

I think this post shows a few different answers to your question.

RoninEngineer
  • 366
  • 2
  • 7
  • 18