Most of the developers ping an internet address or a web site to check whether computer is connected to Internet or not. However there is a much simple and accurate way to achieve this goal which is using an api. I'm sharing the code that you can use in your applications.
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
public static bool IsInternetConnectionAvailable()
{
int d;
return InternetGetConnectedState(out d, 0);
}