Page 1 of 1

thread STA (Single Thread Apartment) after copy CTRL-C

Posted: Wed Feb 19, 2014 2:53 am
by beauto
hi,

i have a bug when i try to copy (after select a line from a datagrid) :

The current thread must be STA (Single Thread Apartment) before OLE calls can be made.

i don't find where or what i can do for resolution of this exception !

thank

Re: thread STA (Single Thread Apartment) after copy CTRL-C

Posted: Thu Feb 20, 2014 8:06 am
by AMitchneck
beauto,

It's hard to diagnose your problem without further information. Is the OLE managed in a thread you created?

You need to set the threads apartment state before it is started (see http://msdn.microsoft.com/en-us/library ... 00%29.aspx). By default, threads will use MTA if not explicitly set before starting the thread.


There are two types of apartment models that can be used for COM objects (such as OLE) they are Single-threaded Apartment model (STA) and Multi-threaded Apartment model (MTA). For the most part, what it breaks down to is synchronization so the COM object doesn't end up in some sort of limbo state. This is especially true for OLE objects which are graphical in nature.

For more information, look at:
http://support.microsoft.com/kb/150777
http://msdn.microsoft.com/en-us/library/ms809971.aspx

Re: thread STA (Single Thread Apartment) after copy CTRL-C

Posted: Thu Feb 20, 2014 10:30 am
by beauto
it's not a real problem because it's only on simulation and not on panel ( not possible to select a line and copy)

perhaps that's come by another scriptcyclique which run ever 300ms and the application become multithread ....

thank for your interest