VSTO 2005 Command Bar opening WinForm problem RRS feed

  • Question

  • I'm developing a VSTO 2005 Outlook Add-In that adds a Command Bar to each Inspector window.  The command bar has a button that opens a Windows Form.  This works great for existing emails using Word as the editor and for new and existing email when Word is not the editor.  When I have a new email using Word as the editor and I click the button to open the form I get the following error:

    ActiveX control cannot be instantiated because the current thread is in a single threaded apartment.

    It seems that the aparment state of the current thread when the call is made to open the form is only MTA when the Inspector is for a new email using Word as the editor - otherwise it's STA.

    I am using the WebBrowser control on the form which can only be used in STA threads.

    Any ideas on how to get around this?

    Tuesday, January 17, 2006 6:48 PM


  • It seems that the ActiveX control is being created on an MTA thread. This makes sense because the CLR is using a delegate to sink the CommandBarButton click event. So, instead of directly creating/showing the WinForm in the click handler, call back from there to the main STA thread and create/show it there.


    Monday, January 23, 2006 10:39 PM