在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式
作者:Debuger 发布时间:May 27, 2022 分类:文章分享
解决办法有两种:
第一种:在主方法上加上[STAThread]特性标签
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LogInForm());
}
第二种:将线程的单元状态设置为单线程单元,thread.SetApartmentState(ApartmentState.STA);
Thread th = new Thread(()=> new Form1().ShowDialog());
th.SetApartmentState(ApartmentState.STA);
th.Start();