Browsing the archives for the WebBrowser Control tag.


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.

1 Comment