System.Threading.ThreadstateException
Posted
by Yasindu
on Stack Overflow
See other posts from Stack Overflow
or by Yasindu
Published on 2010-04-02T11:50:12Z
Indexed on
2010/04/02
11:53 UTC
Read the original article
Hit count: 328
Hi, I'm developing an adding for office powerpoint application. I'm trying to display a description of the object(Customized object) currently dropped on the powerpoint slide in design mode(Design mode of the powerpoint). When i click on my addin the related object description will be displayed on a tabbed window as the first tabpage.
There is a button on the tab page, and when i click on it i need the description to get copied to windows clipboard. I tried this using clipboardclass it throws the following exception, System.Threading.ThreadstateException {"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."}
Code for clipboard: Clipboard.Clear() Clipboard.SetText(lblObjectID.Text)
I searched the net for a solution and got couple of answers like, 1. Put [STAThread] in the main function 2. Thread.CurrentThread.SetApartmentState(ApartmentState.STA) Immediately before your call to SetDataObject.
But I'm not sure where to put the 1st one and the 2nd option didn't work. Can anyone help me please. Thanks.
© Stack Overflow or respective owner