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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:25:06+00:00 2026-06-13T01:25:06+00:00

Possible Duplicate: WebBrowser Control in a new thread I’m trying to automate clicking certain

  • 0

Possible Duplicate:
WebBrowser Control in a new thread

I’m trying to automate clicking certain element on a webpage that then spawn a new IE window on each click.

The code below reads a DataTable with one column containing the element IDs I need to click. It then cycles the table and clicks the required element in the Webbrowser webNav.webBrowser1.

The code works fine the first time it runs but thereafter there are no more click events. If I step through using breakpoints then I can see the code is running fine without a problem. It appears as if it’s scheduling the actions which never get triggered.

This is my first time attempting to use threads so I might be doing something fundamentally wrong.

At the moment I’m a bit stumped as to what the problem is?

[STAThread]
private void ClickOptions()
{
    DataTable _dataTableTestClone = new DataTable();
    _dataTableTestClone = _dataTableTest;

    if (_dataTableTest != null)
    {
        var thread = new Thread(() =>
        {
            foreach (DataRow row in _dataTableTestClone.Rows)
            {
                string getclickID = row["ID"].ToString();

                webNav.webBrowser1.Invoke(new Action(() =>
                {
                    HtmlElement lit = webNav.webBrowser1.Document.GetElementById(getclickID);
                    if (lit != null)
                    {
                        lit.InvokeMember("click");
                    }
                }));

                Thread.Sleep(2000);
            }
        });
        thread.SetApartmentState(ApartmentState.STA);
        thread.IsBackground = true;
        thread.Start();
    }
}
  • 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-06-13T01:25:07+00:00Added an answer on June 13, 2026 at 1:25 am

    Why are you setting the thread apartment state to STA? I don’t think it has any purpose. Only the thread you use to create controls or interact with certain COM objects needs to be STA (which isn’t the thread you are starting there, as the Invoke() call on webBrowser1 will marshal your action to the UI thread).

    You can try wrapping the code on the inside of your Invoke with try/catch and adding a breakpoint to something on the inside of the catch block to see if any exceptions pop up, as exceptions in multithreaded scenarios sometimes act a little funny depending on how the rest of your application is setup. I’m willing to bet you are getting an exception that is being swallowed somewhere.

    EDIT: if the only purpose to your thread is to have a 2 second delay between invoked actions, I would use System.Windows.Forms.Timer instead:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx

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

Sidebar

Related Questions

Possible Duplicate: How do you click a button in a webbrowser control in C#?
Possible Duplicate: How to disable “Security Alert” window in Webbrowser control I'm currently using
Possible Duplicate: Create event handler for OnScroll for web browser control I would like
Possible Duplicate: Python : how to append new elements in a list of list?
Possible Duplicate: How to wrap a Struct into NSObject Can the new Clang Objective-C
Possible Duplicate: Is it possible to hide the cursor in a webpage using CSS
Possible Duplicate: Opening url in new tab while i am doing window.open(), my page
Possible Duplicate: Load local HTML file in a C# WebBrowser I´m creating program in
Possible Duplicate: thread with multiple parameters How does one thread a sub with two
Possible Duplicate: Setting popup window to be a child of MDI Control when using

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.