WebBrowser Control Can’t Be Hosted in Class Library

So my previous initial hunch for a nice, compact architecture for my Snapper project turns out to be unworkable.  The reason?  The WebBrowser control is very finicky and can only be run in a UI thread.  Without claiming to be fully aware of the issues, it has something to do with the single-threaded-apartment (STA) model that WinForms apps use vs. the multi-threaded apartment (MTA) model that is the default for .NET class libraries.

How does this affect my large-scale plans to provide full-page web snapshots to a variety of calling services, including:

  1. Command-line applications
  2. MSBuild tasks
  3. Web Services that return XML, a la Alexa
  4. .ASHX services that return the image inline via HTTP
  5. … and more?

Well, it just got a whole lot more complicated.  Instead of the nice, in-process system I wanted, I now have to deal with .NET ProcessStartInfo() stuff to shell out to a (invisible) WinForms app that will instantiate the WebBrowser control, and save the resulting image somewhere that the calling application or library can access it.  Bah.

Advertisements

1 Response to “WebBrowser Control Can’t Be Hosted in Class Library”


  1. 1 Ofir Yaron July 22, 2008 at 12:03 am

    Hi Anthony,
    I’m having the same problem.
    basically what i need is a page source of a given url
    at first i tried to get it using an ‘HttpWebResponse’ but found out that he cut out the ‘Display: None’ tags, that’s when i tried to use the WebBrowser class and came to your conclusion.

    I’ll appreciate if you have any ideas to share…

    Thanks,
    Ofir Yaron


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: