Use this function
static string GetMeText()
{
string res = "starting value";
Thread staThread = new Thread(x =>
{
try
{
res = Clipboard.GetText();
}
catch (Exception ex)
{
res = ex.Message;
}
});
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
staThread.Join();
return res;
}
In this line:
Console.WriteLine("You copied " + Clipboard.GetMeText());
The problem is that the clipboard only works with certain threading models (ApartmentState.STA) so you have to make a new thread and give it that model this code does that.