COM Interopt - is it all STA or single threaded?
Question -
I'm using the "AxWebBrowser" component and it's requiring that I create the instance using the STA model in my Main() method for my hosting WinForm.
Are all Interopt compoenets STA?
And if not is there a way that I can either:
A) modify the compoent so that I can use MTA
B) a better web browser component that does support MTA.
Thanks!
Viking
Most COM objects (WebBrowser included) are STA, as is the Win32 API itself. If you need to use other threads here, you are best off doing as much work as possible in them and then marshalling over batch updates to the UI thread using Control.Invoke/BeginInvoke.
The only legal Windows Forms call from a thread other than the one that created the control is Control.Invalidate.
Well, this made me look at the docs, 'cause I wondered how I had missed this particular method call being threadsafe. The docs for InvokeRequired say:
"There are four methods on a control that are safe to call from any thread: Invoke, BeginInvoke, EndInvoke and CreateGraphics. For all other method calls, you should use one of these invoke methods when calling from a different thread."
Is there a discrepancy here? Am I missing something? I'm guessing that you're right, and the docs are incomplete.
Just wondering, 'cause I do a lot of public blabbing on threading in Windows forms, it seems... <g> Thanks!