Clipboard and STAThreadAttribute

Clipboard and STAThreadAttribute

am 10.10.2007 23:48:25 von Fir5tSight

I got the error when I execute the following line of code:

Clipboard.SetDataObject(mGrid.Clip);

The error is:

"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."

FYI, I started a separate thread and defined a "Run" method and that's
where I got the error. I don't have to do it this way. However, just
curious why this doesn't work. I'm dying to know why.

Re: Clipboard and STAThreadAttribute

am 11.10.2007 07:21:02 von mattias.dont.want.spam

>FYI, I started a separate thread and defined a "Run" method and that's
>where I got the error. I don't have to do it this way. However, just
>curious why this doesn't work. I'm dying to know why.

You have to set the thread's ApartmentState property to STA when you
start it to use objects like the clipboard.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.