How To : Check Internet Connection In C#

covert
Amm, i think i wrote something about connecting and disconnecting the internet in vb.net 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();  }  
 [DllImport("wininet.dll")]
        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.

2 comments

nice 1. Just have a look into this http://www.etechpulse.com/2014/12/check-internet-connection-available-or-not-in-c.html

Thanks

Reply

Post a Comment

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