Check if I have a Internet connection

RobinJ 276 Reputation points
2020-12-05T21:57:19.153+00:00

Hello everybody,
I need to check if a internet connection exists because the little program i wrote download a file from a server.
I found a example but this isn't working?!

 bool checkInternet = new Ping().Send("google.com", 500).Status == IPStatus.Success;

if (checkInternet == false)
            {
                MessageBoxButton button = MessageBoxButton.OK;
                string caption = "Internet Error";
                MessageBox.Show("Bitte Internetverbindung überprüfen und erneut versuchen.", caption, button);
            }

Does anybody know how I can solve the problem?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,997 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118K Reputation points
    2020-12-05T22:02:01.107+00:00

    Maybe start downloading the file and intercept the errors, including the ones related to connection.

    The result of checking connection is not necessarily valid after the check.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.