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 4332052
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:12:06+00:00 2026-05-21T10:12:06+00:00

I am developing a c# winform app which controls a website using web browser.

  • 0

I am developing a c# winform app which controls a website using web browser. I need to perform many events on click of a single button, but many events do not take place until I use a message box to give some sort of lag between events. Below is the code

private void button5_Click(object sender, EventArgs e)
{
    try
    {
        HtmlDocument webDoc = this.webBrowser1.Document;
        HtmlElementCollection aTags = webDoc.GetElementsByTagName("a");
        string selectedIssue;
        selectedIssue = AcknowledgeList.SelectedItem.ToString();
        foreach (HtmlElement aElement in aTags)
        {
            if (aElement.InnerText.Contains(selectedIssue))
            {
                aElement.InvokeMember("click");

                break;
            }
        }
        MessageBox.Show("Device Acknowledged");

        this.finalAcknowledge();
    }
    catch (NullReferenceException connectionError)
    {
        MessageBox.Show("Connection Error , try again");
    }
}

private void finalAcknowledge()
{
    try
    {
        HtmlDocument webDoc = this.webBrowser1.Document;

        HtmlElement changeNote = webDoc.GetElementById("@note");
        string comment = textBox1.Text;
        changeNote.SetAttribute("value", comment);

        HtmlElementCollection selectTags
            = webDoc.GetElementsByTagName("select");
        foreach (HtmlElement selectElement in selectTags)
        {
            if (selectElement.GetAttribute("name").Equals("status"))
            {
                selectElement.SetAttribute("value", "6");
            }
        }

        HtmlElement submitButton = webDoc.GetElementById("submit_button");
        submitButton.InvokeMember("click");
        this.button3.PerformClick();
        string selectedIssue;
        selectedIssue = AcknowledgeList.SelectedItem.ToString();
        AcknowledgeList.Items.Remove(AcknowledgeList.SelectedItem);
        AssignToList.Items.Add(selectedIssue);

        MessageBox.Show("Device Acknowledged");

        this.callShowAssigned();
    }
    catch (NullReferenceException connectionError)
    {
        MessageBox.Show("Connection Error , try again");
    }
}

Here I have used two message boxes to give some lag between events. I want to get rid of these message boxes and want some other method which can perfrom all the events and I do not have to interrupt the user with some message box or something that is visible

  • 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-21T10:12:07+00:00Added an answer on May 21, 2026 at 10:12 am

    Lag can be done with:

    Thread.Sleep(time_to_sleep);
    

    But in this case better to use event:
    http://msdn.microsoft.com/en-us/library/5d67hf8a.aspx

    webBrowser1.DocumentCompleted+=OnPageLoaded;
    

    When you aElement.InvokeMember(“click”), you tell to webBrowser1 make some action: post/get to some page. So webbrowser begins job: it makes call to remote server, gets page, renders it. This take time, which can be longer or shorter. This call is made asynchronous, which means, that your code runs forward without waiting for webbrowser to finish. So what can you do? You can subscribe to webbrowser object events, which will hit when browser control finish work.

    //Somewhere before InvokeMember
    webBrowser1.DocumentCompleted+=OnPageLoaded;
    
    
    private void OnPageLoaded(object sender,
            WebBrowserDocumentCompletedEventArgs e)
        {
        //Make your final acknowledgement
        //This method will be executed every time, when your page is loaded
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.