Clipboard and STAThreadAttribute

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

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.
 
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
 
Have you find any solution yet?
I have [System.STAThreadAttribute()] marked before my main(). I tried
to delete all dll and rebuilt my project. I am still getting the same
error message while trying to Clipboard.Clear().

Thanks in advance!
 
Back
Top