Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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!

PlayWithForms.zip

Edited by PlausiblyDamp
  • Administrators
Posted

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.

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());
}

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...