How to check internet connection in C#
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:
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;
}
.png)
0 comments: