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

  • Home
  • SEARCH
  • 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 1054749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:27:16+00:00 2026-05-16T17:27:16+00:00

I believe the WebBrowser control is STA and a WCFservice hosted in a NT

  • 0

I believe the WebBrowser control is STA and a WCFservice hosted in a NT Service is MTA ?
Thanks.

  • 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-16T17:27:17+00:00Added an answer on May 16, 2026 at 5:27 pm

    Right, this likely will not work. The WebBrowser control was meant to be used by a single STA thread. It won’t map well to MTA in a web service, and will likely require some major hackery.

    What are you trying to do? If you can describe your problem, we may be able to come up with an alternative solution.


    edit

    Ok, this is probably possible, although certainly hacky. Here’s a theoretical implementation:

    1. Spin up an STA thread, have the web service thread wait for it.
    2. Load the browser in the STA thread.
    3. Navigate to the desired web page. When navigation finishes, take the screenshot.
    4. Send the screenshot back to web service thread.

    The code would look something like this:

    public Bitmap GiveMeScreenshot()
    {
        var waiter = new ManualResetEvent();
        Bitmap screenshot = null;
    
        // Spin up an STA thread to do the web browser work:
        var staThread = new Thread(() =>
        {
            var browser = new WebBrowser();
            browser.DocumentCompleted += (sender, e) => 
            {
                screenshot = TakeScreenshotOfLoadedWebpage(browser);
                waiter.Set(); // Signal the web service thread we're done.
            }
            browser.Navigate("http://www.google.com");
        };
        staThread.SetApartmentState(ApartmentState.STA);
        staThread.Start();
    
        var timeout = TimeSpan.FromSeconds(30);
        waiter.WaitOne(timeout); // Wait for the STA thread to finish.
        return screenshot;
    };
    
    private Bitmap TakeScreenshotOfLoadedWebpage(WebBrowser browser)
    {
        // TakeScreenshot() doesn't exist. But you can do this using the DrawToDC method:
        // http://msdn.microsoft.com/en-us/library/aa752273(VS.85).aspx
        return browser.TakeScreenshot(); 
    }
    

    Also, a note from past experience: we’ve seen issues where the System.Windows.Forms.WebBrowser doesn’t navigate unless it’s added to a visual parent, e.g. a Form. Your mileage may vary. Good luck!

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

Sidebar

Related Questions

Using the IHtmlDocument2.designMode property set to On to switch a WebBrowser control hosted on
I'm using a WebBrowser control in .NET CF 3.5 for a Windows CE device
I use a webbrowser control in my application to get data from a specific
I believe I've set this up correctly. Can somebody see anything wrong with this
I believe I am using the correct queryString params for jdbc connection jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=utf8&noAccessToProcedureBodies=true My
I believe what I am trying to accomplish should be a fairly common task,
I believe that the rallytagpicker is definitely a useful component. However, I do not
I believe I am having a security problem related to using the embed tag
I believe I've looked everywhere possible and already feel to silly because I spent
I believe Wordpress stores multiple entries of posts as revisions but I think thats

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.