0

I have the following code to check the internet connection. The code works well if the test is done once or through the button. The problem comes if I want to check continuously, I used a timer, but the code sometimes works and sometimes stops. I want to continuously scan the Internet without affecting the program interface or causing the interface to stop

//class TIMEDATE_INTER
  public static bool CheckForInternetConnection()
        {
            try
            {
                using (var client = new WebClient())
                using (client.OpenRead("http://google.com/generate_204"))
                    return true;
            }
            catch
            {
                return false;
            }
        }

//timer event
   if (TIMEDATE_INTER.CheckForInternetConnection() == true)
                {

                    label5.Invoke((MethodInvoker)delegate
                    {
                        label5.Text = "internet connect";
                        return;

                    });


                }
                else 
                {
                    label5.Invoke((MethodInvoker)delegate
                    {
                        label5.Text = "internet disconnect";
                        
                        return;
                    });

                    //
                }



FAST2021
  • 37
  • 1
  • 4

0 Answers0