How to Check if Internet connection is available using C#

How to detect working internet connection in C#

using System;
using System.Runtime;
using System.Runtime.InteropServices;
 
public class InternetAvailability
{
    [DllImport("wininet.dll")]
    private extern static bool InternetGetConnectedState(out int description, int reservedValue);
 
    public static bool IsInternetAvailable( )
    {
        int description;
        return InternetGetConnectedState(out description, 0);
    }
}
How to Check if Internet connection is available using C# How to Check if Internet connection is available using C# Reviewed by Bhaumik Patel on 7:39 PM Rating: 5