Lukezzz 0 Posting Whiz in Training

Hello,

I am using a button event to activate a backgroundworker that will copy a string to the Clipboard.

When debugging the code, I get this error for the Clipboard line in the backgroundworker.
I am not sure what this meens or what I need to do here. I have tried to put the [STAThread] attribute like this but it does not solve the problem:

error:
Current thread must be set to singel thread apartment (STA) mode before OLE calls can be made.
Ensure that your Main function has STAThreadAttribute marked on it.

[STAThread]
private: Void button1_Click(Object^ sender, EventArgs^ e)
{
            //Activate backgroundworker
            if (backgroundWorker1->IsBusy == false)
            {
                backgroundWorker1->RunWorkerAsync();
            }
}



private: Void backgroundWorker1_DoWork(Object^ sender, DoWorkEventArgs^ e)
{
           Clipboard->SetText("hello");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.