0

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!!

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by nick.crane
0

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.

Edited by nick.crane: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.