https://social.msdn.microsoft.com/Forums/windows/en-US/2411f889-8e30-4a6d-9e28-8a46e66c0fdb/current-thread-must-be-set-to-single-thread-apartment-sta-mode-before-ole?forum=clr

 

Add the STAThreadAttribute attribute on the Main method. This attribute is required if your program access OLE related functions, like Clipboard class does.

 

 

C#

[STAThread]

static void Main(string[] args)

{

}

 

 

Visual Basic

<STAThread()> _

Shared Sub Main(args As String())

 

End Sub

 

或者

 

    Thread t = new Thread(ThreadProc);
        Console.WriteLine("Before setting apartment state: {0}", 
            t.GetApartmentState());

        t.SetApartmentState(ApartmentState.STA);
        Console.WriteLine("After setting apartment state: {0}", 

 

參考

Tread.SetApartmentState 方法 (ApartmentState)

https://msdn.microsoft.com/zh-tw/library/system.threading.thread.setapartmentstate(v=vs.110).aspx

 

 

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 olivermode 的頭像
    olivermode

    olivermode的部落格

    olivermode 發表在 痞客邦 留言(0) 人氣()