How To : Check Internet Connection In C#

Amm, i think i wrote something about connecting and disconnecting the internet in that's actually a simple matter(process commands) . We are going to use wininet.dll in this tutorial so first of all add this namespace using System.Runtime.InteropServices; after that add this codes after InitializeComponent();  }  
        private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
        bool IsConnectedToInternet()
            bool a;
            int xs;
            a = InternetGetConnectedState(out xs, 0);
            return a;
What those lines of codes does is , it first adds the dll and then creates a function to use the API,So now to check the state of your internet connection let's use a if condition(;).
            if (IsConnectedToInternet() == true) MessageBox.Show("Internet Is Working");
            if (IsConnectedToInternet() == false) MessageBox.Show("Internet Is Not Working");
Just add those lines for a event to check the internet . Thanks For Reading , Peace.


nice 1. Just have a look into this



Post a Comment

Note: Only a member of this blog may post a comment.