C# 请确保您的 Main 函数带有 STAThreadAttribute 标记。”
System.Threading.ThreadStateException:“在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttribute 标记。”
一
在函数头部增加[STAThreadAttribute]。
原代码:
static void Main(string[] args)
{
System.Windows.Forms.Clipboard.SetText("无尽的华尔兹");
}修改后:
[STAThreadAttribute]
static void Main(string[] args)
{
System.Windows.Forms.Clipboard.SetText("无尽的华尔兹");
}二
using System.Threading;
Thread t = new Thread((ThreadStart)(() =>
{
//放入异常语句
}));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();转载请注明出处。