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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:28:58+00:00 2026-05-23T18:28:58+00:00

I use a WebBrowser control as a preview for a special type of markup.

  • 0

I use a WebBrowser control as a “preview” for a special type of markup. I process the markup, and then set the browser’s DocumentText property to display it. This works okay.

However, sometimes the control takes upwards of 5-10 seconds for this operation to complete. Since I do this at application start up (blanking the window with DocumentText = ""), and it still takes forever to do this, I want to somehow Thread this or something so that the rest of the application can start up while the control… does whatever it does.

For reference, the function in question is:

private void btnRefresh_Click(object sender, EventArgs e) {
    try {
        scrolltop = html.Document.Body.ScrollTop;
        scrollleft = html.Document.Body.ScrollLeft;
    } catch (NullReferenceException) { }

    html.DocumentText = HtmlProcessing.ProcessCode(txtCode.Text); //takes 5-10 seconds
}

I know I can’t just fire up a thread to handle this, since I assume the WebBrowser control will puke if I try to access it from the other thread. Are there any other techniques I could use to do this?


Edit:

Turns out, my delay was not being caused by html.DocumentText, nor by HtmlProcessing.ProcessCode, but by a bit of code that I omitted from the sample, because I thought it was irrelevant:

private void btnRefresh_Click(object sender, EventArgs e) {
    try {
        scrolltop = html.Document.Body.ScrollTop;
        scrollleft = html.Document.Body.ScrollLeft;
    } catch (NullReferenceException) { }

    html.DocumentText = HtmlProcessing.ProcessCode(txtCode.Text, GetImageList());
}

That call to GetImageList() was taking forever. The contents of the function looks like:

List<string> GetImageList() {
    List<string> ret = new List<string>();

    ret.AddRange(Directory.GetFiles(settings.LocalImageFolder).Where((f) => { return extensions.Contains(Path.GetExtension(f)); }));

    ret.AddRange(Directory.GetFiles(settings.RemoteImageFolder).Where((f) => { return extensions.Contains(Path.GetExtension(f)); }));

    return ret;
}

And, settings.RemoteImageFolder is, in fact, a network path that was taking forever. I ended up turning this into an IEnumerable<string>. That way, I only hit the network when ProcessCode actually needs files from there.

  • 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-23T18:28:58+00:00Added an answer on May 23, 2026 at 6:28 pm

    The problem was a slow network access that was hidden behind a property accessor, and had nothing to do with the web browser control.

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

Sidebar

Related Questions

As the WebBrowser control does not expose a get accessor for the DocumentText property
Using the IHtmlDocument2.designMode property set to On to switch a WebBrowser control hosted on
I've set up my Silverlight WP7 app to use a WebBrowser Control to allow
When you use the WebBrowser control in .NET you can embed an instance of
Is it possible to use the WebBrowser control as a UI interface in C#?
I use Javascript to click a link in the webbrowser control. But I don't
I want to use the Web Browser control within an mono application, but when
Is it possible/recommended to use background worker threads with the web browser control? I
Currently I use .Net WebBrowser.Document.Images() to do this. It requires the Webrowser to load
I want to use WebBrowser control to load some localfile html page. I am

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.