How to Check Internet Connection using C#

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10. using System.Net.NetworkInformation;  
  11. namespace internet  
  12. {  
  13.     public partial class internet : Form  
  14.     {  
  15.         public bool check_connection;  
  16.         public internet()  
  17.         {  
  18.             InitializeComponent();  
  19.         }  
  20.   
  21.         private void internet_Load(object sender, EventArgs e)  
  22.         {  
  23.             check_connection = NetworkInterface.GetIsNetworkAvailable();  
  24.             if(check_connection)  
  25.             {  
  26.                 this.pictureBox1.Image = global::internet.Properties.Resources._4;  
  27.                 label1.Text = "Connected";  
  28.             }  
  29.         }  
  30.     }  
  31. }