How to check internet connection in C#

April 04, 2017 , , 0 Comments

Sometimes we need to know that our internet connection is available or nor. In using those code, you know that your internet connection  available or nor. This is a boolean function and this output true or false. If your internet connection lost that's message 'false' or have connection that message 'true'



Code:
using System.Net.NetworkInformation; public bool IsConnectedToInternet() { string host = http://www.google.com; bool result = false; Ping ping = new Ping(); try { PingReply reply = ping .Send(host, 3000); if (reply.Status == IPStatus.Success) return true; } catch { } return result; }

Kamrul

Love to code and explore new idea. He also loves write, travel and more enjoy. Always want to learn new technology.

0 comments: