通过异步线程创建一个什么都不带的FORM时,是没有问题的。但是我自己封装了一个通讯组件,把这个组件放在FORM上,通过异步线程去创建时就出错了:当前线程不在单线程单元中,无法实例化ActiveX控件。主窗体源码:
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(Open)); t.Start();
} private void Open()
{
Form2 f2 = new Form2();
f2.ShowDialog();
}被创建窗体的源码:
this.communicationToolBar1 = new EntlogicCommunicationClient.CommunicationToolBar();
communicationToolBar1 就是自定义的组件,上述语句就提示错误了
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(Open)); t.Start();
} private void Open()
{
Form2 f2 = new Form2();
f2.ShowDialog();
}被创建窗体的源码:
this.communicationToolBar1 = new EntlogicCommunicationClient.CommunicationToolBar();
communicationToolBar1 就是自定义的组件,上述语句就提示错误了
t.ApartmentState = System.Threading.ApartmentState.STA;