How to display a message box if there is no internet C#

Hemanth B 886 Reputation points
2021-06-17T07:38:45.737+00:00

How to display a message box if there is no internet connection in the system in C#? Pls provide the code for that!

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,819 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 84,281 Reputation points
    2021-06-17T08:00:23.777+00:00

    A way =>

    if(IsInternetConnected() == 0)
        MessageBox.Show("Connected to Internet");
    else
        MessageBox.Show("Not connected to Internet");
    

    Declaration :

        [DllImport("Connect.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        public static extern HRESULT IsInternetConnected();
    

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.