Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7051425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:15:43+00:00 2026-05-28T03:15:43+00:00

I am working on a small app in C# that refreshes a web page

  • 0

I am working on a small app in C# that refreshes a web page until some conditions are met. I have a “Fire” = start refreshing button and a “Stop!” button that is supposed to stop the operation. My problem is that it takes 2 tries to click the stop button instead of 1. Below is my code:

Updated code with timer. Still I think there can be some better use of the timer, I think that it doesn’t update every second after the first 2-3 refreshes or doesn’t refresh at all. Is there any flaw in my code that I can’t detect?

private void FireButtonClick(object sender, EventArgs e)
{

    try
    {
        if (webBrowser1.Url.ToString().StartsWith("some url"))
        {
            _stopped = false;
            _timer.Tick += new EventHandler(RefreshBrowser);
            _timer.Interval = (1000) * (1);
            _timer.Enabled = true;
            _timer.Start();
       }
        else
        {
            MessageBox.Show("You must logon first.");
            return;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

private void RefreshBrowser(object sender, EventArgs e)
{
    string content = "disabled";
    string baseUrl = @"http://some url";
    string newUrl = string.Empty;
    string buttonXpath = @"/html/body/div/div[6]/table/tr/td[2]/table/tr/td/table/tr/td/table/tr[3]/td[2]/div[4]/a";
    webBrowser1.Refresh();
    _proceed = false;
    if (!content.ToLower().Equals("disabled") && !_stopped)
    {

        if (!_stopped)
        {
            HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
            htmlDocument.LoadHtml(webBrowser1.DocumentText);
            HtmlNode node = htmlDocument.DocumentNode.SelectSingleNode(buttonXpath);
            content = node.GetAttributeValue("disabled", string.Empty);
            newUrl = node.GetAttributeValue("href", string.Empty);
        }
    }
    else
    {

        webBrowser1.Navigate(baseUrl + newUrl);
    }


}

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
    _proceed = true;
    urlTextBox.Text = webBrowser1.Url.ToString();
}

private void MainPageButtonClick(object sender, EventArgs e)
{
    try
    {
        webBrowser1.Navigate(_mainPage);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

private void GoButtonClick(object sender, EventArgs e)
{
    try
    {
        webBrowser1.Navigate(urlTextBox.Text);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

}

private void StopButtonClick(object sender, EventArgs e)
{
    _timer.Stop();
    _proceed = true;
    _stopped = true;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:15:44+00:00Added an answer on May 28, 2026 at 3:15 am

    You should really modify your code to use a timer. When you misuse the GUI thread and make periodic calls to Application.DoEvents(); the click can only handled at that place meaning you have to enter the loop to process the event.

    This is an absolute no go for GUI programming. Use a timer instead.

    Here is an example on how a timer can be used to periodically call a method. In your case to perform the refresh of the page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m currently working on a small web app that allows people to search for
I'm working in a small company and weeks away from deploying a web-app that
I used to have a small chat app(which was almost working), that uses PHP,
I have a small IPhone app that I am working on and I am
I have been working on a small web app using the Stripes framework. Now
I am working on a small app that will use threads to make some
I've been working on a small iPhone app that displays web content using the
I have a small app where the index page is a form that instructs
I'm working with this small web application (1 page) built by someone else that
I am working on an existing ASP.NET MVC app that started small and has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.