Browsing the archives for the Snapper 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

WebBrowser.DocumentComplete Firing Multiple Times: Solution

Software

My previous hunch was correct: before you do any actual work in the DocumentComplete event handler, make sure the ReadyState of the control equals “Complete”.

Here’s the updated diagnostic output: notice the time taken drops to three seconds now that I’m not looping through the worker code eleven different times.

'Snapper.WinForm.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Uninitialized
Uninitialized
Uninitialized
Uninitialized
Uninitialized
'Snapper.WinForm.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll'
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
12/29/2007 1:15:03 PM - DocumentCompleted!
12/29/2007 1:15:03 PM - DocumentCompleted!
Interactive
Interactive
Interactive
12/29/2007 1:15:03 PM - DocumentCompleted!
12/29/2007 1:15:03 PM - DocumentCompleted!
Interactive
Interactive
Interactive
Interactive
Interactive
12/29/2007 1:15:05 PM - DocumentCompleted!
12/29/2007 1:15:05 PM - DocumentCompleted!
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
12/29/2007 1:15:05 PM - DocumentCompleted!
12/29/2007 1:15:05 PM - DocumentCompleted!
12/29/2007 1:15:05 PM - DocumentCompleted!
12/29/2007 1:15:05 PM - DocumentCompleted!
Interactive
12/29/2007 1:15:06 PM - DocumentCompleted!
Complete
12/29/2007 1:15:06 PM - DocumentCompleted!
Doing work..

It’s probably also the case that the WebBrowserDocumentCompletedEventArgs parameter of the DocumentCompleted event handler gives me additional info with which to discriminate this ReadyState. May have to look into that one.

8 Comments

WebBrowser.DocumentCompleted Firing Multiple Times

Software

I’m running in to the same problem that Adi ran into wherein the DocumentCompleted event of the WebBrowser control is firing more than once. Sometimes a lot of times!

Seems to me that this should be a Once and Only Once type of thing.

Here’s my diagnostic output when I open techcrunch.com: the timestamped lines are the DocumentCompleted events; the others are the ProgressChanged events.

'Snapper.WinForm.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Uninitialized
Uninitialized
Uninitialized
Uninitialized
Uninitialized
'Snapper.WinForm.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll'
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
12/29/2007 1:00:23 PM - DocumentCompleted!
12/29/2007 1:00:24 PM - DocumentCompleted!
12/29/2007 1:00:25 PM - DocumentCompleted!
Interactive
Interactive
12/29/2007 1:00:27 PM - DocumentCompleted!
12/29/2007 1:00:29 PM - DocumentCompleted!
Interactive
Interactive
Interactive
Interactive
Interactive
12/29/2007 1:00:31 PM - DocumentCompleted!
Interactive
Interactive
Interactive
Interactive
Interactive
Interactive
12/29/2007 1:00:33 PM - DocumentCompleted!
Interactive
12/29/2007 1:00:35 PM - DocumentCompleted!
12/29/2007 1:00:36 PM - DocumentCompleted!
Interactive
Interactive
12/29/2007 1:00:40 PM - DocumentCompleted!
Complete
12/29/2007 1:00:41 PM - DocumentCompleted!

Aside from the fact that it took 18 seconds to get this page’s contents in code (whereas FasterFox reports 8 seconds in Flock), having 11 DocumentCompleted events seems a little odd.

UPDATE: Looking at this the answer seems to pop out at me.  Just wait for the ProgressChanged event to change to “Complete” before I do anything meaningful in the DocumentCompleted event handler.  I’ll give that a try right now.

1 Comment

Snapper Back-of-the-Envelope Design for Command Line Version

Software

Snapper Command-Line App

Initial plan for the command-line app version of the little project I’ve taken to calling “Snapper”.

Technorati Tags:

2 Comments