Accessing WebBrowser on different Threads

Accessing WebBrowser on different Threads

Content Index :

Accessing WebBrowser on different Threads
Tag : chash , By : Bart van Bragt
Date : November 24 2020, 03:41 PM

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Tag : chash , By : TRobison
Date : March 29 2020, 07:55 AM
like below fixes the issue Try SWAT or WatiN
Both are unit testing frameworks for automating web site front end testing, but can easily be used to traverse the DOM on a website as you want to do.

Accessing DOM from WebBrowser

Tag : chash , By : user185144
Date : March 29 2020, 07:55 AM
should help you out For the System.Windows.Controls.WebBrowser class you can use the Document property. Add mshtml reference to your project that should be available by right click on project and selecting Add Reference, then you should be able to cast it to mshtml.IHTMLDocument2
mshtml.IHTMLDocument2 htmlDoc = webBrowser.Document as mshtml.IHTMLDocument2;
// do something like find button and click

Threads for WebBrowser.Print()

Tag : chash , By : Kuer
Date : March 29 2020, 07:55 AM
To fix this issue Main problem with your code is WebBrowser wrong using.
WebBrowser supposed to be used for interactive web-browsing, during it user do some things in the internet. But in your case you are using WebBrowser just for the printing after downloading the html. This is wrong by two reasons:
  ref obj, 

WebBrowser Threads don't seem to be closing

Tag : chash , By : vbanos
Date : March 29 2020, 07:55 AM
this will help WebBrowser is specifically designed to be used from inside a windows forms project. It is not designed to be used from outside a windows forms project.
Among other things, it is specifically designed to use an application loop, which would exist in pretty much any desktop GUI application. You don't have this, and this is of course causing problems for you because the browser leverages this for its event based style of programming.
public static string GetGeneratedHTML(string url)
    string result = null;
    ThreadStart pumpMessages = () =>
        EventHandler idleHandler = null;
        idleHandler = (s, e) =>
            Application.Idle -= idleHandler;

            WebBrowser wb = new WebBrowser();
            wb.DocumentCompleted += (s2, e2) =>
                result = wb.Document.Body.InnerHtml;
        Application.Idle += idleHandler;
    if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
        Thread t = new Thread(pumpMessages);
    return result;

InvalidCastException when using webbrowser and threads in c#

Tag : chash , By : hammer_1968
Date : March 29 2020, 07:55 AM
it helps some times The WebBrowser doesn't like being accessed from other threads. Try passing it in to RunWorkerAsync() like this:
    private void button1_Click(object sender, EventArgs e)
        HtmlDocument doc = web.Document;

    void m_oWorker_DoWork(object sender, DoWorkEventArgs e)
        HtmlDocument doc = (HtmlDocument)e.Argument;

        //NOTE : Never play with the UI thread here...
        string line;

        //time consuming operation
        while ((line = sr.ReadLine()) != null)
            int index = line.IndexOf(":");


            //If cancel button was pressed while the execution is in progress
            //Change the state from cancellation ---> cancel'ed
            if (m_oWorker.CancellationPending)
                e.Cancel = true;


        //Report 100% completion on operation completed
Related Posts Related QUESTIONS :
  • How to access .Net element on Master page from a Content page?
  • Why are unsigned int's not CLS compliant?
  • Why is Array.Length an int, and not an uint
  • How do I make event callbacks into my win forms thread safe?
  • Genealogy Tree Control
  • WCF Service - Backward compatibility issue
  • Binary patch-generation in C#
  • Tab Escape Character?
  • When do Request.Params and Request.Form differ?
  • The imported project "C:\Microsoft.CSharp.targets" was not found
  • Numeric Data Entry in WPF
  • Print a Winform/visual element
  • C# logic order and compiler behavior
  • When to use an extension method with lambda over LINQtoObjects to filter a collection?
  • How to make a button appear as if it is pressed?
  • C# and Arrow Keys
  • How do you resolve a domain name to an IP address with .NET/C#?
  • Should the folders in a solution match the namespace?
  • How can I evaluate C# code dynamically?
  • CSharpCodeProvider Compilation Performance
  • How can I create Prototype Methods (like JavaScript) in C#.Net?
  • DataTable Loop Performance Comparison
  • CSV string handling
  • What is the best way to do unit testing for ASP.NET 2.0 web pages?
  • High availability
  • What to use for Messaging with C#
  • Accessing a Dictionary.Keys Key through a numeric index
  • ConfigurationManager.AppSettings Performance Concerns
  • What Are Some Good .NET Profilers?
  • Is this a good way to determine OS Architecture?
  • How to create a tree-view preferences dialog type of interface in C#?
  • Searching directories for tons of files?
  • Can I have a method returning IEnumerator<T> and use it in a foreach loop?
  • Why can't I have abstract static methods in C#?
  • Displaying ad content from Respose.WriteFile()/ Response.ContentType
  • Convert integers to written numbers
  • Absolute path back to web-relative path
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com