C# Clipboard error?...

Wing

Newcomer
Joined
May 13, 2007
Messages
15
Location
Sweden
Well here is my problem i got a multi thread/form project. and if i try to use the clipboard on any other from then the "start form" i get a thread error....

sample code included.

Tnx for any help!
 

Attachments

Last edited by a moderator:
It looks as though there is some COM stuff going on behind the scenes when accessing the clipboard - one of the issues you need to be careful with is different threading models and how COM copes (or not) with them.

When you know though the fix is easy... change the button click event in your form1 to the following and it should work.
C#:
private void button1_Click(object sender, EventArgs e)
{
ParameterizedThreadStart p = new ParameterizedThreadStart(Run);
Thread t = new Thread(p);
t.SetApartmentState(ApartmentState.STA);//set the correct threading model and all is good.
t.Start(new Form2());
}
 
Back
Top