WebBrowser Control Can’t Be Hosted in Class Library

Software

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.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Furl
  • Ma.gnolia
  • Reddit
  • TwitThis
1 Comment

1 Comment

  1. Ofir Yaron  •  Jul 22, 2008 @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

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">