This is really killing me...

For this to function:

if (Clipboard.ContainsText())

The static void main has to be marked [STAThread] (which it is)
But then later when i check the thread it's MTA (I think because the app uses com somewhere).

So i thought ill thread the class that needs the clipboard (which has no com in it).
But how can i thread a new class instance?

Thanks!!

Classes do not run in threads, methods do.
In case you have not solved this, here is my solution:

public void MySTAMethod()
{
    Debug.WriteLine(string.Format("Thread ApartmentState = {0}", Thread.CurrentThread.GetApartmentState()));
    if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
    {
        Thread t = new Thread(new ThreadStart(MySTAMethod));
        t.SetApartmentState(ApartmentState.STA);
        t.Start();
    }
    else 
    {
        Debug.WriteLine(string.Format("Clipboard.ContainsText() = {0}", Clipboard.ContainsText()));
    }
}

Its a bit crude, but I'm sure you can adapt it to suit your needs.

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.