469,332 Members | 7,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Activator.CreateInstance locks in STAThread

Hi,
Does any one know why the creation of a COM object in .NET works when
it runs in the "Main" thread of a console application if the STAThread
tag is used, but same code causes the call to
Activator.CreateInstance(Type) locks up when called from another
thread, even though the thread has been set to STA?

Thanks in advance,
Ashley

Jun 22 '07 #1
3 5895
<as*********@gmail.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
Hi,
Does any one know why the creation of a COM object in .NET works when
it runs in the "Main" thread of a console application if the STAThread
tag is used, but same code causes the call to
Activator.CreateInstance(Type) locks up when called from another
thread, even though the thread has been set to STA?

Thanks in advance,
Ashley

What is the "ThreadingModel" of it's class as it is stored in the registry?

Willy.

Jun 22 '07 #2
What is the "ThreadingModel" of it's class as it is stored in the registry?
>
Willy.
Hi Willy,

I did wonder about this as there is no String value defined for
ThreadingModel in the InprocServer32 KEY for the CLIS of the Object.I
do not have the source for the object, but I know that it is written
in Delphi and is an .ocx file type. Not sure what difference this
makes?I have tried setting the threading apartment to MTA and STA, but
both cause it to hang when calling Activator.CreateInstance. Tried
early binding with a new statement, but again this causes it to hang.

Cheers

Ashley

Jun 22 '07 #3
<as*********@gmail.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
>What is the "ThreadingModel" of it's class as it is stored in the
registry?

Willy.

Hi Willy,

I did wonder about this as there is no String value defined for
ThreadingModel in the InprocServer32 KEY for the CLIS of the Object.I
do not have the source for the object, but I know that it is written
in Delphi and is an .ocx file type. Not sure what difference this
makes?I have tried setting the threading apartment to MTA and STA, but
both cause it to hang when calling Activator.CreateInstance. Tried
early binding with a new statement, but again this causes it to hang.

Cheers

Ashley
If there is no ThreadingModel specified, then it is considered "Single",
that means that the component is not designed to be accessed from multiple
threads, changing the model toe "Apartment" is in general not a good idea,
as the component was not really designed to live in an STA other than the
'main STA'. The "main STA" is the STA thread created by the COM
infrastructure, not your applications main thread.
Note that I say "Apartment", MTA or STA are NO legal values for
"ThreadingModel". I for one would never use such an object in today's code,
it was written for singled threaded applications, .NET applications are
multi-threaded by default.

Willy.
Jun 22 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by David Sworder | last post: by
2 posts views Thread by shmeian | last post: by
3 posts views Thread by System.Reflection Activator | last post: by
1 post views Thread by Johnny R | last post: by
reply views Thread by Jon Skeet [C# MVP] | last post: by
reply views Thread by =?Utf-8?B?QW5kcmV3?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.