'How to make program (c#, selenium) wait to periodically check if the 'if' condition is met

I intend to increment the counter by 1 when the url changes and return the final count, eg 10 if url changes 10 times. The program has to wait until the user clicks a button or something on the webpage which leads to the change of url. The code isn't giving the desired output, infact the counter isn't incrementing at all.

    public partial class Counter : Form 
    {    
        int count = 0;
        string url = "...";
        private IWebDriver driver = new ChromeDriver();
        
        public Counter()
        {
        
           InitializeComponen();
           driver.Navigate().GoToUrl(url);
        }
        
        private void textBox.TextChanged(object sender, EventArgs e)
        {
            textBox.Text = "Click: " + count.ToString();
            driver.Manage().Timeout().ImplicitWait = TimeSpan.FromSeconds(10);
            if (driver.Url != url)
            {
                 count++;
                 textBox.Text = "Click: " + count.ToString();
        
            }
        }
        
            private void resetButton_Click(object sender, EventArgs e)
            {
                count = 0;
                textBox.Text = "Click: " + count.ToString();
        
            }
        }
   }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source