This works for me:
You want to do:
System.Windows.Forms.Clipboard.SetText("String to be copied to Clipboard");
But it causes an error saying it must be in a single thread of ApartmentState.STA.
So let's make it run in such a thread. The code for it:
public void somethingToRunInThread()
{
System.Windows.Forms.Clipboard.SetText("String to be copied to Clipboard");
}
protected void copy_to_clipboard()
{
Thread clipboardThread = new Thread(somethingToRunInThread);
clipboardThread.SetApartmentState(ApartmentState.STA);
clipboardThread.IsBackground = false;
clipboardThread.Start();
}
After calling copy_to_clipboard(), the string is copied into the clipboard, so you can Paste or Ctrl + V and get back the string as String to be copied to the clipboard.