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:
- Command-line applications
- MSBuild tasks
- Web Services that return XML, a la Alexa
- .ASHX services that return the image inline via HTTP
- … 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.