views:

160

answers:

1

I have developed a library to manipulate HTML to conform to our needs using the WebBrowser control, however I need this library to work on a web app and not a winforms app. The main issue I get is this:

"ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment."

I understand this is because the WebBrowser control needs to be ran in a STA Thread, but obviously a web app isn't an STA environment. Its a server side process though so its not in a page itself. Any ideas on how I can get round this? I considered setting the AspCompat="true" attribute on the Page tag of a hidden page and running it from that but I would rather a more elegant solution.

Cheers

A: 

Instantiate and perform your work in a new thread upon which you have explicitly set the ApartmentState via SetApartmentState().

Sky Sanders