COM interopt all STA?

Sorry for the cross post...

Question: Are all interopt components used in WinForms forced to be STA threading model? Its seems this might be a serious limitation if this is true.

Thanks,

Eric

[197 byte] By [codefund.com] at [2007-12-16]
# 1
This really isn't up to Windows Forms, it's a limitation of the underlying systems. Most COM objects are STA, as are the Windows APIs themselves.

We are working on ways to make it easier to program against this model, however. In the meantime, you need to make sure you only call Windows Forms classes and wrapped COM objects on the thread which created them. See the Control.Invoke/Begin invoke methods for ways of doing this.

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
Hi,

STA is ok for most situations. However, once I deploy my application as a smart client, All calls to COMs fail due to the threading model

Also, the dragdrop registration fail as well. Is there a work around?

Is there any article that talks about the threading model between a thick and a smart client?

Thanks

Thomas

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
Make sure you have the STAThreadAttribute on your Main.

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
We had the same problem, and the [STAThread] attribute seems to be ignored when hosted in IEEXEC.EXE. We solved the problem by making the following call the first thing in the Main function:

System.Threading.Thread.CurrentThread.ApartmentState = System.Threading.ApartmentState.STA;

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...